Skip to content

Instantly share code, notes, and snippets.

@LarryLuTW
Last active August 9, 2020 04:16
Show Gist options
  • Save LarryLuTW/ad6500696461e7f6606eeebc94f23dce to your computer and use it in GitHub Desktop.
Save LarryLuTW/ad6500696461e7f6606eeebc94f23dce to your computer and use it in GitHub Desktop.
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