@@ -4,6 +4,10 @@ import { COOKIE_NAME } from '@/lib/cookies';
4
4
import {
5
5
loginService ,
6
6
registerService ,
7
+ checkEmailValidService ,
8
+ checkUsernameValidService ,
9
+ type IEmailValidPayload ,
10
+ type IUsernameValidPayload ,
7
11
type ILoginPayload ,
8
12
type IRegisterPayload ,
9
13
} from '@/services/auth' ;
@@ -69,3 +73,29 @@ export const register: IRouteHandler = async (req, res) => {
69
73
user : data . user , // Return user data if needed
70
74
} ) ;
71
75
} ;
76
+
77
+ export const checkUsernameValid : IRouteHandler = async ( req , res ) => {
78
+ const { username } : IUsernameValidPayload = req . body ;
79
+ if ( ! username ) {
80
+ return res . status ( StatusCodes . UNPROCESSABLE_ENTITY ) . json ( 'Malformed Request' ) ;
81
+ }
82
+ const { code, data, error } = await checkUsernameValidService ( { username } ) ;
83
+ if ( error || code !== StatusCodes . OK || ! data ) {
84
+ const sanitizedErr = error ?. message ?? 'An error occurred.' ;
85
+ return res . status ( code ) . json ( sanitizedErr ) ;
86
+ }
87
+ return res . status ( StatusCodes . OK ) . json ( data ) ;
88
+ } ;
89
+
90
+ export const checkEmailValid : IRouteHandler = async ( req , res ) => {
91
+ const { email } : IEmailValidPayload = req . body ;
92
+ if ( ! email ) {
93
+ return res . status ( StatusCodes . UNPROCESSABLE_ENTITY ) . json ( 'Malformed Request' ) ;
94
+ }
95
+ const { code, data, error } = await checkEmailValidService ( { email } ) ;
96
+ if ( error || code !== StatusCodes . OK || ! data ) {
97
+ const sanitizedErr = error ?. message ?? 'An error occurred.' ;
98
+ return res . status ( code ) . json ( sanitizedErr ) ;
99
+ }
100
+ return res . status ( StatusCodes . OK ) . json ( data ) ;
101
+ } ;
0 commit comments