Last active
August 9, 2020 04:16
-
-
Save LarryLuTW/ad6500696461e7f6606eeebc94f23dce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = require('./db') | |
async function signup({ username, password }) { | |
// 1. 先檢查密碼長度是否大於 6 | |
if (password.length < 6) { | |
throw new Error('password is too short') | |
} | |
// 2. 再檢查 username 有沒有被用過 | |
if (await db.isUserExist(username)) { | |
throw new Error('username exists') | |
} | |
// 3. 呼叫 db.createUser 把使用者資料存進資料庫 | |
await db.createUser(username, password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment