@@ -3,7 +3,11 @@ import jwt from "jsonwebtoken";
3
3
import { findUserById as _findUserById } from "../model/repository" ;
4
4
import { AuthenticatedRequest } from "../types/request" ;
5
5
6
- export function verifyAccessToken ( req : AuthenticatedRequest , res : Response , next : NextFunction ) {
6
+ export function verifyAccessToken (
7
+ req : AuthenticatedRequest ,
8
+ res : Response ,
9
+ next : NextFunction
10
+ ) {
7
11
const authHeader = req . headers [ "authorization" ] ;
8
12
if ( ! authHeader ) {
9
13
return res . status ( 401 ) . json ( { message : "Authentication failed" } ) ;
@@ -25,22 +29,36 @@ export function verifyAccessToken(req: AuthenticatedRequest, res: Response, next
25
29
req . user = {
26
30
id : dbUser . id ,
27
31
username : dbUser . username ,
32
+ firstName : dbUser . firstName ,
33
+ lastName : dbUser . lastName ,
28
34
email : dbUser . email ,
35
+ biography : dbUser . biography ,
36
+ profilePictureUrl : dbUser . profilePictureUrl ,
29
37
isAdmin : dbUser . isAdmin ,
30
38
} ;
31
39
next ( ) ;
32
40
} ) ;
33
41
}
34
42
35
- export function verifyIsAdmin ( req : AuthenticatedRequest , res : Response , next : NextFunction ) {
43
+ export function verifyIsAdmin (
44
+ req : AuthenticatedRequest ,
45
+ res : Response ,
46
+ next : NextFunction
47
+ ) {
36
48
if ( req . user ?. isAdmin ) {
37
49
next ( ) ;
38
50
} else {
39
- return res . status ( 403 ) . json ( { message : "Not authorized to access this resource" } ) ;
51
+ return res
52
+ . status ( 403 )
53
+ . json ( { message : "Not authorized to access this resource" } ) ;
40
54
}
41
55
}
42
56
43
- export function verifyIsOwnerOrAdmin ( req : AuthenticatedRequest , res : Response , next : NextFunction ) {
57
+ export function verifyIsOwnerOrAdmin (
58
+ req : AuthenticatedRequest ,
59
+ res : Response ,
60
+ next : NextFunction
61
+ ) {
44
62
if ( req . user ?. isAdmin ) {
45
63
return next ( ) ;
46
64
}
@@ -52,5 +70,7 @@ export function verifyIsOwnerOrAdmin(req: AuthenticatedRequest, res: Response, n
52
70
return next ( ) ;
53
71
}
54
72
55
- return res . status ( 403 ) . json ( { message : "Not authorized to access this resource" } ) ;
73
+ return res
74
+ . status ( 403 )
75
+ . json ( { message : "Not authorized to access this resource" } ) ;
56
76
}
0 commit comments