Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let user = await this.db.findUserByServiceId(params.provider, oauthUser.id);
if (!user && oauthUser.email) {
user = await this.db.findUserByEmail(oauthUser.email);
}
if (!user) {
try {
const userId = await this.db.createUser({
email: oauthUser.email,
});
user = (await this.db.findUserById(userId)) as User;
if (this.server) {
await this.server.getHooks().emit(ServerHooks.CreateUserSuccess, user);
}
} catch (e) {
if (this.server) {
await this.server.getHooks().emit(ServerHooks.CreateUserError, user);
}
throw e;
}
}
await this.db.setService(user.id, params.provider, oauthUser);
return user;
}
defer(async () => {
if (this.options.sendVerificationEmailAfterSignup && user.email)
this.sendVerificationEmail(user.email);
const userRecord = (await this.db.findUserById(userId)) as User;
this.server.getHooks().emit(ServerHooks.CreateUserSuccess, userRecord);
});