mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
fix: fix createUser without password
This commit is contained in:
1 parent
d3945eeaa7
commit
f81c96be62
3 files changed
+5
-4
No files matched your search
@@ -16,7 +16,7 @@ export const issueToken = asyncHandler(async (req, res) => {
|
|||||||
export const register = asyncHandler(async (req, res, next) => {
|
export const register = asyncHandler(async (req, res, next) => {
|
||||||
const { username, password, email } = matchedData(req)
|
const { username, password, email } = matchedData(req)
|
||||||
|
|
||||||
const user = await createUser(username, email, password)
|
const user = await createUser(username, email, { password })
|
||||||
req.login(user, (err) => {
|
req.login(user, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err)
|
next(err)
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ export async function createUser(username, email, { password, socialLogin }) {
|
|||||||
})
|
})
|
||||||
if (password) {
|
if (password) {
|
||||||
user.hashedPassword = await hashPassword(password)
|
user.hashedPassword = await hashPassword(password)
|
||||||
}
|
} else if (socialLogin) {
|
||||||
if (socialLogin) {
|
|
||||||
user.socialLogins.set(socialLogin.provider, socialLogin)
|
user.socialLogins.set(socialLogin.provider, socialLogin)
|
||||||
|
} else {
|
||||||
|
throw new Error('No password or social login provided')
|
||||||
}
|
}
|
||||||
await user.save()
|
await user.save()
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ export default async function setupTest() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await createUser(username, email, password)
|
await createUser(username, email, { password })
|
||||||
console.log('Created testing account')
|
console.log('Created testing account')
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user