Skip to content

Commit dfcd2b0

Browse files
committed
feat: Add authorization token to request interceptor
1 parent 217c9a9 commit dfcd2b0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/lib/interceptors/DefaultRequestInterceptor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { AxiosRequestConfig } from 'axios'
22
import { API_ENDPOINT } from 'src/config'
33
import { isProduction } from 'src/utils/Environment'
4+
import { firebaseAuth } from '../firebase'
45

5-
export function DefaultRequestInterceptor(config: AxiosRequestConfig) {
6+
export async function DefaultRequestInterceptor(config: AxiosRequestConfig) {
67
if (config) {
78
config.baseURL = isProduction() ? API_ENDPOINT : '/api'
89
if (config.headers) {
910
config.headers.Accept = 'application/json'
1011
}
12+
13+
const user = firebaseAuth.currentUser
14+
if (user) {
15+
const token = await user.getIdToken()
16+
config.headers.Authorization = `Bearer ${token}`
17+
}
1118
}
1219

1320
return config

0 commit comments

Comments
 (0)