@@ -9,7 +9,7 @@ import * as tokenService from '../../services/token.service'
99import * as userService from '../../services/user.service'
1010import * as authValidation from '../../validations/auth.validation'
1111
12- const register : Handler < { Bindings : Bindings } > = async ( c ) => {
12+ export const register : Handler < { Bindings : Bindings } > = async ( c ) => {
1313 const config = getConfig ( c . env )
1414 const bodyParse = await c . req . json ( )
1515 const body = await authValidation . register . parseAsync ( bodyParse )
@@ -18,7 +18,7 @@ const register: Handler<{ Bindings: Bindings }> = async (c) => {
1818 return c . json ( { user, tokens } , httpStatus . CREATED as StatusCode )
1919}
2020
21- const login : Handler < { Bindings : Bindings } > = async ( c ) => {
21+ export const login : Handler < { Bindings : Bindings } > = async ( c ) => {
2222 const config = getConfig ( c . env )
2323 const bodyParse = await c . req . json ( )
2424 const { email, password } = authValidation . login . parse ( bodyParse )
@@ -27,15 +27,15 @@ const login: Handler<{ Bindings: Bindings }> = async (c) => {
2727 return c . json ( { user, tokens } , httpStatus . OK as StatusCode )
2828}
2929
30- const refreshTokens : Handler < { Bindings : Bindings } > = async ( c ) => {
30+ export const refreshTokens : Handler < { Bindings : Bindings } > = async ( c ) => {
3131 const config = getConfig ( c . env )
3232 const bodyParse = await c . req . json ( )
3333 const { refresh_token } = authValidation . refreshTokens . parse ( bodyParse )
3434 const tokens = await authService . refreshAuth ( refresh_token , config )
3535 return c . json ( { ...tokens } , httpStatus . OK as StatusCode )
3636}
3737
38- const forgotPassword : Handler < { Bindings : Bindings } > = async ( c ) => {
38+ export const forgotPassword : Handler < { Bindings : Bindings } > = async ( c ) => {
3939 const bodyParse = await c . req . json ( )
4040 const config = getConfig ( c . env )
4141 const { email } = authValidation . forgotPassword . parse ( bodyParse )
@@ -56,7 +56,7 @@ const forgotPassword: Handler<{ Bindings: Bindings }> = async (c) => {
5656 return c . body ( null )
5757}
5858
59- const resetPassword : Handler < { Bindings : Bindings } > = async ( c ) => {
59+ export const resetPassword : Handler < { Bindings : Bindings } > = async ( c ) => {
6060 const queryParse = c . req . query ( )
6161 const bodyParse = await c . req . json ( )
6262 const config = getConfig ( c . env )
@@ -69,15 +69,15 @@ const resetPassword: Handler<{ Bindings: Bindings }> = async (c) => {
6969 return c . body ( null )
7070}
7171
72- const sendVerificationEmail : Handler < { Bindings : Bindings } > = async ( c ) => {
72+ export const sendVerificationEmail : Handler < { Bindings : Bindings } > = async ( c ) => {
7373 const config = getConfig ( c . env )
7474 const payload = c . get ( 'payload' ) as JwtPayload
7575 const userId = Number ( payload . sub )
7676 // Don't let bad actors know if the email is registered by returning an error if the email
7777 // is already verified
7878 try {
7979 const user = await userService . getUserById ( userId , config . database )
80- if ( user . is_email_verified ) {
80+ if ( ! user || user . is_email_verified ) {
8181 throw new Error ( )
8282 }
8383 const verifyEmailToken = await tokenService . generateVerifyEmailToken ( user , config . jwt )
@@ -94,21 +94,11 @@ const sendVerificationEmail: Handler<{ Bindings: Bindings }> = async (c) => {
9494 return c . body ( null )
9595}
9696
97- const verifyEmail : Handler < { Bindings : Bindings } > = async ( c ) => {
97+ export const verifyEmail : Handler < { Bindings : Bindings } > = async ( c ) => {
9898 const config = getConfig ( c . env )
9999 const queryParse = c . req . query ( )
100100 const { token } = authValidation . verifyEmail . parse ( queryParse )
101101 await authService . verifyEmail ( token , config )
102102 c . status ( httpStatus . NO_CONTENT as StatusCode )
103103 return c . body ( null )
104- }
105-
106- export {
107- register ,
108- login ,
109- refreshTokens ,
110- sendVerificationEmail ,
111- forgotPassword ,
112- resetPassword ,
113- verifyEmail
114- }
104+ }
0 commit comments