-
Notifications
You must be signed in to change notification settings - Fork 694
Open
Labels
Description
I use the TokenObtainPairView and TokenRefreshView to handle the JWT stuff.
The initial request to refresh token happens successfully, but the second time it happens it doesnt and fails with an error saying "token has wrong type".
Frontend:
Next.js
settings.py ( btw i also tried it with rotate set to false ie the default , still doesnt work )
SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=15),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
"ROTATE_REFRESH_TOKENS": True,
}
the refreshing code:
"use client"
import React from 'react'
import { useState } from 'react'
import { REFRESH_TOKEN , ACCESS_TOKEN} from '@/constants'
import axios from 'axios'
import { toast } from 'sonner'
const page = () => {
const [ response , setResponse ] = useState()
const handlerefresh = async () =>{
const refreshtoken = localStorage.getItem(REFRESH_TOKEN)
const data={refresh:refreshtoken}
console.log(data)
const resp = await axios.post("http://127.0.0.1:8000/api/token/refresh/",data)
localStorage.setItem(REFRESH_TOKEN,resp.data?.access)
localStorage.setItem(ACCESS_TOKEN,resp.data?.refresh)
toast.success("access and refresh REFRESHED !")
setResponse(resp.data?.access)
}
return (
<div className='h-screen w-screen flex items-centre justify-center flex-col'>
<div className='border w-full h-28 text-neutral-50'>
{response}
</div>
<button className='h-fit active:bg-neutral-700 cursor-pointer' onClick={handlerefresh}>Refresh</button>
</div>
)
}
export default page
the error :
"{\"detail\":\"Token has wrong type\",\"code\":\"token_not_valid\"}"