@@ -55,33 +55,41 @@ class Authentication {
5555 "It appears you do not have an account using this email, please contact your Codr admin to gain access." ,
5656 } ) ;
5757 } else if ( ! token ) {
58- try {
59- // init access token
60- const uuid = uuidv4 ( ) ;
61- const accessToken = new AccessToken ( uuid ) ;
62- await user . updateOne ( {
63- accessToken : accessToken . encode ( ) ,
64- } ) ;
65-
66- // send email with access code/token
67- const link =
68- `${ process . env . HOST } ${ process . env . API_PATH } ` +
69- "/auth/email/verify?token=" +
70- encrypt ( JSON . stringify ( { email : email , token : uuid } ) ) ;
71- const template = new SigninTemplate ( ) ;
72- await Mail . send ( await template . html ( { link } ) , {
73- ...template . config ,
74- to : email ,
75- } ) ;
76- return new Response ( {
77- message : "An email has been sent to your inbox." ,
78- } ) ;
79- } catch ( e : any ) {
58+ if ( user . flags . isDisabled ) {
8059 throw new Error ( {
8160 status : 500 ,
82- message : e ?. message || "An unknown error occured" ,
83- details : e ,
61+ message :
62+ "It appears that your account has been disabled or deleted. Please contact your administrator if you feel like this is a mistake." ,
8463 } ) ;
64+ } else {
65+ try {
66+ // init access token
67+ const uuid = uuidv4 ( ) ;
68+ const accessToken = new AccessToken ( uuid ) ;
69+ await user . updateOne ( {
70+ accessToken : accessToken . encode ( ) ,
71+ } ) ;
72+
73+ // send email with access code/token
74+ const link =
75+ `${ process . env . HOST } ${ process . env . API_PATH } ` +
76+ "/auth/email/verify?token=" +
77+ encrypt ( JSON . stringify ( { email : email , token : uuid } ) ) ;
78+ const template = new SigninTemplate ( ) ;
79+ await Mail . send ( await template . html ( { link } ) , {
80+ ...template . config ,
81+ to : email ,
82+ } ) ;
83+ return new Response ( {
84+ message : "An email has been sent to your inbox." ,
85+ } ) ;
86+ } catch ( e : any ) {
87+ throw new Error ( {
88+ status : 500 ,
89+ message : e ?. message || "An unknown error occured" ,
90+ details : e ,
91+ } ) ;
92+ }
8593 }
8694 } else if ( user . accessToken ) {
8795 // decrypt the stored access code
@@ -116,7 +124,7 @@ class Authentication {
116124 // send response
117125 return new Response < { user : IUser } > ( {
118126 message : `Login successful.` ,
119- details : { user : { ...user . toObject ( ) , ...update } } ,
127+ details : { user : { ...user . toObject ( ) , ...update } } ,
120128 } ) ;
121129 } catch ( e : any ) {
122130 throw new Error ( {
0 commit comments