@@ -2,6 +2,7 @@ import { Response } from 'express';
22import { AuthService } from 'omniboxd/auth/auth.service' ;
33import { LocalAuthGuard } from 'omniboxd/auth/local-auth.guard' ;
44import { Public } from 'omniboxd/auth/decorators/public.auth.decorator' ;
5+ import { UserId } from 'omniboxd/decorators/user-id.decorator' ;
56import { ConfigService } from '@nestjs/config' ;
67import {
78 Res ,
@@ -11,9 +12,15 @@ import {
1112 UseGuards ,
1213 Controller ,
1314 HttpCode ,
15+ Query ,
1416} from '@nestjs/common' ;
1517import { ResourcePermission } from 'omniboxd/permissions/resource-permission.enum' ;
1618import { NamespaceRole } from 'omniboxd/namespaces/entities/namespace-member.entity' ;
19+ import {
20+ SendEmailOtpDto ,
21+ VerifyEmailOtpDto ,
22+ SendEmailOtpResponseDto ,
23+ } from './dto/email-otp.dto' ;
1724
1825@Controller ( 'api/v1' )
1926export class AuthController {
@@ -45,60 +52,77 @@ export class AuthController {
4552 }
4653
4754 @Public ( )
48- @Post ( 'sign-up' )
49- async signUp ( @Body ( 'url' ) url : string , @Body ( 'email' ) email : string ) {
50- return await this . authService . signUp ( url , email ) ;
55+ @Post ( 'auth/send-otp' )
56+ @HttpCode ( 200 )
57+ async sendEmailOtp (
58+ @Body ( ) dto : SendEmailOtpDto ,
59+ @Body ( 'url' ) url : string ,
60+ ) : Promise < SendEmailOtpResponseDto > {
61+ return await this . authService . sendOTP ( dto . email , url ) ;
62+ }
63+
64+ @Public ( )
65+ @Post ( 'auth/send-signup-otp' )
66+ @HttpCode ( 200 )
67+ async sendSignupOtp (
68+ @Body ( ) dto : SendEmailOtpDto ,
69+ @Body ( 'url' ) url : string ,
70+ ) : Promise < SendEmailOtpResponseDto > {
71+ return await this . authService . sendSignupOTP ( dto . email , url ) ;
5172 }
5273
5374 @Public ( )
54- @Post ( 'sign-up/confirm' )
55- async signUpConfirm (
56- @Body ( 'token' ) token : string ,
57- @Body ( 'username' ) username : string ,
58- @Body ( 'password' ) password : string ,
75+ @Post ( 'auth/verify-otp' )
76+ @HttpCode ( 200 )
77+ async verifyEmailOtp (
78+ @Body ( ) dto : VerifyEmailOtpDto ,
5979 @Res ( ) res : Response ,
6080 @Body ( 'lang' ) lang ?: string ,
6181 ) {
62- const signUpData = await this . authService . signUpConfirm ( token , {
63- username ,
64- password ,
82+ const authData = await this . authService . verifyOTP (
83+ dto . email ,
84+ dto . code ,
6585 lang ,
66- } ) ;
86+ ) ;
6787
6888 const jwtExpireSeconds = parseInt (
6989 this . configService . get ( 'OBB_JWT_EXPIRE' , '2678400' ) ,
7090 10 ,
7191 ) ;
72- res . cookie ( 'token' , signUpData . access_token , {
92+ res . cookie ( 'token' , authData . access_token , {
7393 httpOnly : true ,
7494 secure : true ,
7595 sameSite : 'none' ,
7696 path : '/' ,
7797 maxAge : jwtExpireSeconds * 1000 ,
7898 } ) ;
7999
80- return res . json ( signUpData ) ;
81- }
82-
83- @Public ( )
84- @Post ( 'password' )
85- async password ( @Body ( 'url' ) url : string , @Body ( 'email' ) email : string ) {
86- return await this . authService . password ( url , email ) ;
100+ return res . json ( authData ) ;
87101 }
88102
89103 @Public ( )
90- @Post ( 'password/confirm ' )
91- async resetPassword (
92- @ Body ( 'token' ) token : string ,
93- @Body ( 'password ') password : string ,
104+ @Post ( 'auth/verify-magic ' )
105+ @ HttpCode ( 200 )
106+ async verifyMagicLink (
107+ @Query ( 'token ') token : string ,
94108 @Res ( ) res : Response ,
109+ @Body ( 'lang' ) lang ?: string ,
95110 ) {
96- const result = await this . authService . resetPassword ( token , password ) ;
97- res . clearCookie ( 'token' , {
111+ const authData = await this . authService . verifyMagicLink ( token , lang ) ;
112+
113+ const jwtExpireSeconds = parseInt (
114+ this . configService . get ( 'OBB_JWT_EXPIRE' , '2678400' ) ,
115+ 10 ,
116+ ) ;
117+ res . cookie ( 'token' , authData . access_token , {
98118 httpOnly : true ,
119+ secure : true ,
120+ sameSite : 'none' ,
99121 path : '/' ,
122+ maxAge : jwtExpireSeconds * 1000 ,
100123 } ) ;
101- return res . json ( result ) ;
124+
125+ return res . json ( authData ) ;
102126 }
103127
104128 @Post ( 'invite' )
@@ -140,8 +164,33 @@ export class AuthController {
140164 }
141165
142166 @Post ( 'invite/confirm' )
143- async inviteConfirm ( @Body ( 'token' ) token : string ) {
144- return await this . authService . inviteConfirm ( token ) ;
167+ async inviteConfirm ( @UserId ( ) userId : string , @Body ( 'token' ) token : string ) {
168+ return await this . authService . inviteConfirm ( token , userId ) ;
169+ }
170+
171+ @Public ( )
172+ @Post ( 'auth/accept-invite' )
173+ @HttpCode ( 200 )
174+ async acceptInvite (
175+ @Query ( 'token' ) token : string ,
176+ @Res ( ) res : Response ,
177+ @Body ( 'lang' ) lang ?: string ,
178+ ) {
179+ const authData = await this . authService . acceptInvite ( token , lang ) ;
180+
181+ const jwtExpireSeconds = parseInt (
182+ this . configService . get ( 'OBB_JWT_EXPIRE' , '2678400' ) ,
183+ 10 ,
184+ ) ;
185+ res . cookie ( 'token' , authData . access_token , {
186+ httpOnly : true ,
187+ secure : true ,
188+ sameSite : 'none' ,
189+ path : '/' ,
190+ maxAge : jwtExpireSeconds * 1000 ,
191+ } ) ;
192+
193+ return res . json ( authData ) ;
145194 }
146195
147196 @Post ( 'logout' )
0 commit comments