This repository was archived by the owner on Apr 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,14 @@ export const getEmailObject = async (email: string) => {
100100 ) ) [ 0 ] ;
101101} ;
102102
103- export const getUserVerifiedEmails = async ( userId : number ) => {
103+ export const getUserVerifiedEmails = async ( user : User | number ) => {
104+ let userId = 0 ;
105+ if ( typeof user === "object" && user . id ) {
106+ userId = user . id ;
107+ } else if ( typeof user === "number" ) {
108+ userId = user ;
109+ }
110+ if ( ! userId ) throw new Error ( ErrorCode . USER_NOT_FOUND ) ;
104111 return < Email [ ] > (
105112 await query ( "SELECT * FROM emails WHERE userId = ? AND isVerified = 1" , [
106113 userId
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ export enum ErrorCode {
4848 INVALID_LOGIN = "401/invalid-login" ,
4949 INSUFFICIENT_PERMISSION = "401/insufficient-permission" ,
5050 DEFAULT = "500/server-error" ,
51- EMAIL_CANNOT_DELETE = "400/email.cannotDelete"
51+ EMAIL_CANNOT_DELETE = "400/email.cannotDelete" ,
52+ UNVERIFIED_EMAIL = "401/unverified-email"
5253}
5354
5455export enum Templates {
Original file line number Diff line number Diff line change 11import { User } from "../interfaces/tables/user" ;
22import { createUser , updateUser , getUserByEmail , getUser } from "../crud/user" ;
33import { InsertResult } from "../interfaces/mysql" ;
4- import { createEmail , updateEmail , getEmail } from "../crud/email" ;
4+ import {
5+ createEmail ,
6+ updateEmail ,
7+ getEmail ,
8+ getUserVerifiedEmails
9+ } from "../crud/email" ;
510import { mail } from "../helpers/mail" ;
611import {
712 verifyToken ,
@@ -45,6 +50,8 @@ export const login = async (
4550 locals : Locals
4651) => {
4752 const user = await getUserByEmail ( email , true ) ;
53+ const verifiedEmails = await getUserVerifiedEmails ( user ) ;
54+ if ( ! verifiedEmails . length ) throw new Error ( ErrorCode . UNVERIFIED_EMAIL ) ;
4855 if ( ! user . password ) throw new Error ( ErrorCode . MISSING_PASSWORD ) ;
4956 if ( ! user . id ) throw new Error ( ErrorCode . USER_NOT_FOUND ) ;
5057 const correctPassword = await compare ( password , user . password ) ;
You can’t perform that action at this time.
0 commit comments