first commit
This commit is contained in:
1 parent
b27f4f2f23
commit
db10146ecd
58 files changed
+3684
-202
No files matched your search
@@ -0,0 +1,70 @@
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user