70 lines
1.4 KiB
TypeScript
70 lines
1.4 KiB
TypeScript
import { cookies } from 'next/headers'
|
|
|
|
|
|
export async function GET(request: Request, context: { params: any }) {
|
|
|
|
|
|
//return Response.json("aaaa")
|
|
|
|
const cookiesList = await cookies()
|
|
const refreshToken = await cookiesList.get('refreshToken')
|
|
|
|
|
|
const res = await fetch( "http://localhost:8000/auth/token/refresh/", {
|
|
method: "POST",
|
|
cache: "no-store",
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
refresh: refreshToken?.value
|
|
})
|
|
})
|
|
|
|
|
|
const data = await res.json()
|
|
|
|
if ('access' in data && 'refresh' in data){
|
|
|
|
await cookies().set({
|
|
name: 'accsessToken',
|
|
value:data.access,
|
|
httpOnly: true,
|
|
path: '/',
|
|
})
|
|
|
|
cookies().set({
|
|
name: 'refreshToken',
|
|
value:data.refresh,
|
|
httpOnly: true,
|
|
path: '/',
|
|
})
|
|
|
|
cookies().set({
|
|
name: 'isAuth',
|
|
value:'true',
|
|
path: '/',
|
|
})
|
|
|
|
return new Response(JSON.stringify(data),{
|
|
status: res.status,
|
|
headers: res.headers
|
|
});
|
|
} else {
|
|
|
|
/*cookies().set({
|
|
name: 'isAuth',
|
|
value:'false',
|
|
path: '/',
|
|
})*/
|
|
|
|
return new Response(JSON.stringify(data),{
|
|
status: res.status,
|
|
headers: res.headers
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
} |