Skip to content

Commit 2081e0c

Browse files
committed
feat: 신규 유저, 기존 유저 리다이렉트 구현
1 parent 9ef51cc commit 2081e0c

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/config/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const googleStrategy = new GoogleStrategy(
1919
});
2020

2121
if (isExist) {
22-
done(null, isExist);
22+
done(null, { ...isExist, isNew: false });
2323
} else {
2424
const newUser = await prisma.user.create({
2525
data: {
@@ -29,7 +29,7 @@ export const googleStrategy = new GoogleStrategy(
2929
},
3030
});
3131

32-
done(null, newUser);
32+
done(null, { ...newUser, isNew: true });
3333
}
3434
} catch (error) {
3535
done(error);

src/controller/user_controller.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export class UserController extends Controller {
2929
*/
3030
@Get('/auth/google/callback')
3131
public async googleCallback(@Request() req: ExpressRequest): Promise<void> {
32-
const { user_id, email } = req.user; // Passport Strategy에서 done(null, user)로 넘겨준 데이터
32+
const { user_id, email, isNew } = req.user as any; // Passport Strategy에서 done(null, user)로 넘겨준 데이터
33+
34+
console.log(req.user);
3335

3436
if (!user_id) {
3537
throw new UserNotFoundError();
@@ -48,9 +50,16 @@ export class UserController extends Controller {
4850
// 4. Access Token은 JSON 응답으로 보내거나 쿼리 파라미터로 리다이렉트
4951
// 프론트엔드 대시보드로 리다이렉트 시 예시:
5052
// 나중에 실제 주소로 리다이렉트 할 것
51-
req.res.redirect(
52-
`http://localhost:5173/onboarding?accessToken=${accessToken}&refreshToken=${refreshToken}`,
53-
);
53+
54+
if (isNew) {
55+
req.res.redirect(
56+
`http://localhost:5173/signup?accessToken=${accessToken}&refreshToken=${refreshToken}`,
57+
);
58+
} else {
59+
req.res.redirect(
60+
`http://localhost:5173/onboarding?accessToken=${accessToken}&refreshToken=${refreshToken}`,
61+
);
62+
}
5463
}
5564

5665
@Get('/info')

0 commit comments

Comments
 (0)