1
- import express from "express " ;
2
- import { NextFunction } from "express" ;
1
+ import axios , { HttpStatusCode } from "axios " ;
2
+ import express , { NextFunction } from "express" ;
3
3
import { Auth } from "firebase-admin/auth" ;
4
- import { handleCustomError , handleServerError } from "../utils" ;
5
4
import { StatusMessageType } from "../types" ;
6
- import axios , { HttpStatusCode } from "axios " ;
5
+ import { handleCustomError , handleServerError } from "../utils " ;
7
6
8
7
const getFirebaseMiddleware = ( firebaseAuth : Auth ) => {
9
8
return async (
@@ -14,10 +13,14 @@ const getFirebaseMiddleware = (firebaseAuth: Auth) => {
14
13
try {
15
14
const firebaseToken = req . get ( "firebase-token" ) ;
16
15
if ( ! firebaseToken ) {
17
- handleCustomError ( res , {
18
- type : StatusMessageType . ERROR ,
19
- message : "No Firebase token provided" ,
20
- } ) ;
16
+ handleCustomError (
17
+ res ,
18
+ {
19
+ type : StatusMessageType . ERROR ,
20
+ message : "No Firebase token provided" ,
21
+ } ,
22
+ 401
23
+ ) ;
21
24
return ;
22
25
}
23
26
@@ -40,19 +43,27 @@ const getFirebaseMiddleware = (firebaseAuth: Auth) => {
40
43
! usersResponse . data . payload ||
41
44
! usersResponse . data . payload . role
42
45
) {
43
- handleCustomError ( res , {
44
- type : StatusMessageType . ERROR ,
45
- message :
46
- "Error while fetching user profile. Please try again later!" ,
47
- } ) ;
46
+ handleCustomError (
47
+ res ,
48
+ {
49
+ type : StatusMessageType . ERROR ,
50
+ message :
51
+ "Error while fetching user profile. Please try again later!" ,
52
+ } ,
53
+ 401
54
+ ) ;
48
55
return ;
49
56
}
50
57
51
58
if ( usersResponse . data . payload . role != "admin" ) {
52
- handleCustomError ( res , {
53
- type : StatusMessageType . ERROR ,
54
- message : "Only an authorized admin can perform this action!" ,
55
- } ) ;
59
+ handleCustomError (
60
+ res ,
61
+ {
62
+ type : StatusMessageType . ERROR ,
63
+ message : "Only an authorized admin can perform this action!" ,
64
+ } ,
65
+ 401
66
+ ) ;
56
67
return ;
57
68
}
58
69
}
0 commit comments