@@ -34,7 +34,17 @@ app.get('/', (_: Request, res: Response) => {
34
34
} ) ;
35
35
36
36
app . get ( '/check' , ( req : Request , res : Response ) => {
37
- const token = req . headers [ 'jwt-access-token' ] ;
37
+ const authorization = req . headers . authorization || '' ;
38
+
39
+ if ( ! authorization . includes ( 'Bearer' ) ) {
40
+ return res . status ( 422 ) . json ( {
41
+ status : false ,
42
+ message : 'Missing authentication.' ,
43
+ metadata : { }
44
+ } ) ;
45
+ }
46
+
47
+ const token = authorization . replace ( 'Bearer ' , '' ) ;
38
48
39
49
if ( token ) {
40
50
const validation = authManager . validateToken ( token ) ;
@@ -60,7 +70,7 @@ app.get('/login', async (req: Request, res: Response) => {
60
70
} ) ;
61
71
}
62
72
63
- const [ _ , hash ] = basicAuth . split ( 'Basic ' ) ;
73
+ const hash = basicAuth . replace ( 'Basic ' , ' ') ;
64
74
const credentials = Buffer . from ( hash , 'base64' ) . toString ( 'ascii' ) ;
65
75
const [ username , password ] = credentials . split ( ':' ) ;
66
76
@@ -78,7 +88,12 @@ app.get('/login', async (req: Request, res: Response) => {
78
88
} ) ;
79
89
80
90
app . post ( '/validate' , async ( req : Request , res : Response ) => {
81
- const { username, password, code } = req . body ;
91
+ const { code } = req . body ;
92
+ const basicAuth = req . headers . authorization || '' ;
93
+
94
+ const hash = basicAuth . replace ( 'Basic ' , '' ) ;
95
+ const credentials = Buffer . from ( hash , 'base64' ) . toString ( 'ascii' ) ;
96
+ const [ username , password ] = credentials . split ( ':' ) ;
82
97
83
98
if ( ! username || ! password || ! code ) {
84
99
return res . status ( 422 ) . json ( {
@@ -128,7 +143,12 @@ app.post('/register', async (req: Request, res: Response) => {
128
143
} ) ;
129
144
130
145
app . post ( '/validate-user' , async ( req : Request , res : Response ) => {
131
- const { username, password, code } = req . body ;
146
+ const { code } = req . body ;
147
+ const basicAuth = req . headers . authorization || '' ;
148
+
149
+ const hash = basicAuth . replace ( 'Basic ' , '' ) ;
150
+ const credentials = Buffer . from ( hash , 'base64' ) . toString ( 'ascii' ) ;
151
+ const [ username , password ] = credentials . split ( ':' ) ;
132
152
133
153
if ( ! username || ! password || ! code ) {
134
154
return res . status ( 422 ) . json ( {
@@ -161,17 +181,17 @@ app.post('/request-password-reset', async (req: Request, res: Response) => {
161
181
} ) ;
162
182
163
183
app . post ( '/reset-password' , async ( req : Request , res : Response ) => {
164
- const { username , password, code } = req . body ;
184
+ const { password, code } = req . body ;
165
185
166
- if ( ! username || ! password || ! code ) {
186
+ if ( ! password || ! code ) {
167
187
return res . status ( 422 ) . json ( {
168
188
status : false ,
169
189
message : 'Missing fields.' ,
170
190
metadata : { }
171
191
} ) ;
172
192
}
173
193
174
- const response = await authManager . resetPassword ( username , password , code ) ;
194
+ const response = await authManager . resetPassword ( code , password ) ;
175
195
const statusCode = response . status ? 200 : 400 ;
176
196
177
197
return res . status ( statusCode ) . json ( response ) ;
0 commit comments