Added backend request logic & admin page placeholders, along with some tweaks to frontend design
This commit is contained in:
1 parent
696181a772
commit
0907f0b66b
21 files changed
+447
-20
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class AuthInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
// Retrieve the token from localStorage
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (token) {
|
||||
// Clone the request and add the Authorization header
|
||||
const clonedRequest = req.clone({
|
||||
setHeaders: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
// Pass the cloned request to the next handler
|
||||
return next.handle(clonedRequest);
|
||||
}
|
||||
|
||||
// If no token, continue without adding the Authorization header
|
||||
return next.handle(req);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user