forked from CenterForOpenScience/angular-osf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhybrid-auth.interceptor.ts
More file actions
29 lines (21 loc) · 827 Bytes
/
hybrid-auth.interceptor.ts
File metadata and controls
29 lines (21 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { HttpInterceptorFn } from '@angular/common/http';
import { cookieAuthInterceptor } from './cookie-auth.interceptor';
import { environment } from 'src/environments/environment';
export const hybridAuthInterceptor: HttpInterceptorFn = (req, next) => {
if (environment.cookieAuth.enabled) {
return cookieAuthInterceptor(req, next);
}
console.warn('Using fallback token authentication - this should not happen in production!');
const authToken = 'UlO9O9GNKgVzJD7pUeY53jiQTKJ4U2znXVWNvh0KZQruoENuILx0IIYf9LoDz7Duq72EIm';
if (authToken) {
const authReq = req.clone({
setHeaders: {
Authorization: `Bearer ${authToken}`,
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json',
},
});
return next(authReq);
}
return next(req);
};