Skip to content

Commit fb9c76a

Browse files
committed
feat: implement getUserToken function using firebase authentication
1 parent 605eeff commit fb9c76a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/lib/interceptors/DefaultRequestInterceptor.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InternalAxiosRequestConfig } from 'axios'
22
import { API_ENDPOINT } from 'src/config'
3-
import { getUserToken } from 'src/features/auth'
43
import { isProduction } from 'src/utils/Environment'
4+
import { firebaseAuth } from '../firebase'
55

66
export async function DefaultRequestInterceptor(config: InternalAxiosRequestConfig) {
77
if (config) {
@@ -20,3 +20,18 @@ export async function DefaultRequestInterceptor(config: InternalAxiosRequestConf
2020

2121
return config
2222
}
23+
24+
const getUserToken = async () => {
25+
return new Promise((resolve, _) => {
26+
const unsub = firebaseAuth.onAuthStateChanged(async (user) => {
27+
if (user) {
28+
const token = await user.getIdToken()
29+
resolve(token)
30+
} else {
31+
resolve(null)
32+
}
33+
unsub()
34+
})
35+
resolve('abc')
36+
})
37+
}

0 commit comments

Comments
 (0)