-
Notifications
You must be signed in to change notification settings - Fork 0
/
tobeusedlater.ts
48 lines (44 loc) · 2.03 KB
/
tobeusedlater.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// axios_instance.interceptors.response.use(
// response => response, //return successful response directly
// async error => {
// const originalrequest = error.config;
// if(error.response.status == 401 && !originalrequest._retry){
// originalrequest._retry = true //mark the request retried to aviod infinite loops
// try{
// const response = await axios.post(`${process.env.BACKEND_URL}/auth/refresh/`,{
// refresh : decryptToken(session?.refresh_token)
// })
// const access = response.data.access
// const refresh = response.data.refresh
// const data = response.data.data
// const encodedsession = await encode({
// secret : process.env.NEXTAUTH_SECRET as string,
// token : {
// access_token : access,
// refresh_token : refresh,
// user : {
// userId : data.id,
// name : data.full_name,
// image : data.profile_img,
// email : data.email
// }
// },
// maxAge : 30 * 24 * 60 * 60
// })
// const cookiestore = cookies()
// cookiestore.set('next-auth.session-token',encodedsession,{
// httpOnly : true,
// sameSite : 'lax',
// maxAge : 30 * 24 * 60 * 60
// })
// await getSession()
// axios_instance.defaults.headers.common['Authorization'] = `Bearer ${access}`
// originalrequest.headers['Authorization'] = `Bearer ${access}`
// return axios_instance(originalrequest)
// }catch(error){
// return Promise.reject(error)
// }
// }
// return Promise.reject(error)
// }
// )