BREAKING: change user social login schema

This commit is contained in:
wancat committed 2023-11-18 16:29:37 +08:00
1 parent 9e935b320a
commit 81581c4635
8 files changed
+59 -32

No files matched your search

+9 -2
View File
@@ -1,16 +1,23 @@
import { User, UserProfile } from '@linux-odyssey/models'
import { hashPassword } from '../utils/auth.js'
export async function createUser(username, email, password) {
export async function createUser(username, email, { password, socialLogin }) {
const user = new User({
username,
email,
})
user.hashedPassword = await hashPassword(password)
if (password) {
user.hashedPassword = await hashPassword(password)
}
if (socialLogin) {
user.socialLogins.set(socialLogin.provider, socialLogin)
}
await user.save()
const userProfile = new UserProfile({
user,
})
await userProfile.save()
return user
}