feat: implement authentication with JWT and user management
This commit is contained in:
parent
b7279a85ca
commit
c8c82af4b8
42 changed files with 989 additions and 397 deletions
|
@ -1,21 +1,33 @@
|
|||
import { HttpInterceptorFn } from '@angular/common/http';
|
||||
import { inject } from '@angular/core';
|
||||
import { OAuthStorage } from 'angular-oauth2-oidc';
|
||||
import { AuthService } from '../../service/auth.service';
|
||||
|
||||
export const httpInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const oauthStorage = inject(OAuthStorage);
|
||||
const authService = inject(AuthService);
|
||||
const token = authService.getToken();
|
||||
|
||||
if (oauthStorage.getItem('access_token')) {
|
||||
// Always add CORS headers
|
||||
if (token) {
|
||||
return next(
|
||||
req.clone({
|
||||
setHeaders: {
|
||||
Authorization: 'Bearer ' + oauthStorage.getItem('access_token'),
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Referrer-Policy': 'no-referrer',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
},
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return next(req);
|
||||
return next(
|
||||
req.clone({
|
||||
setHeaders: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
Reference in a new issue