@@ -4,12 +4,16 @@ import {
44 forbidden ,
55 noPassword ,
66 notfound ,
7- serviceUnavailable ,
87 wrongPassword ,
98} from "@/lib/error/api" ;
109import { users } from "@litespace/models" ;
1110import { NextFunction , Request , Response } from "express" ;
12- import { isSamePassword , registerNewStudent , withImageUrl } from "@/lib/user" ;
11+ import {
12+ isSamePassword ,
13+ registerNewStudent ,
14+ registerNewTutor ,
15+ withImageUrl ,
16+ } from "@/lib/user" ;
1317import { IUser } from "@litespace/types" ;
1418import { email , password , string } from "@/validation/utils" ;
1519import { googleConfig , jwtSecret } from "@/constants" ;
@@ -121,22 +125,21 @@ async function loginWithGoogle(
121125 if ( user && role && role !== user . role ) return next ( bad ( ) ) ;
122126 if ( user && ( ! role || role === user . role ) ) return await success ( user ) ;
123127
124- const register = ! user ;
125- if ( register && ! role ) return next ( bad ( ) ) ;
126- if ( register ) {
127- // TODO: remove this condition once the turor onboarding is finalized.
128- if ( role === IUser . Role . Tutor ) return next ( serviceUnavailable ( ) ) ;
129-
130- const { user } = await registerNewStudent ( {
131- email : data . email ,
132- verifiedEmail : data . verified ,
133- role,
134- } ) ;
135-
136- return await success ( user ) ;
137- }
138-
139- return next ( notfound . user ( ) ) ;
128+ const canRegister = ! user && role !== undefined ;
129+ if ( ! canRegister ) return next ( notfound . user ( ) ) ;
130+
131+ const { user : registeredUser } =
132+ role === IUser . Role . Student
133+ ? await registerNewStudent ( {
134+ email : data . email ,
135+ verifiedEmail : data . verified ,
136+ } )
137+ : await registerNewTutor ( {
138+ email : data . email ,
139+ verifiedEmail : data . verified ,
140+ } ) ;
141+
142+ return await success ( registeredUser ) ;
140143}
141144
142145async function loginWithAuthToken (
0 commit comments