AttributeError: 'RefreshToken' object has no attribute 'blacklist_after'

33 Views Asked by At

I am working on a django project. I am using a custom user model (not using django's Abstract User or anything)

during Verify OTP i am using

if not user.refresh_token or RefreshToken(user.refresh_token).blacklist_after:
        refresh = RefreshToken.for_user(user)
        user.refresh_token = str(refresh)
        user.save()
    else:
        refresh = RefreshToken(user.refresh_token)

    access_token = str(refresh.access_token)

and I am getting the error: AttributeError: 'RefreshToken' object has no attribute 'blacklist_after'

My Question is that is there anyway that if the RefreshToken is expired in the database, make a new one and store it in the User Object by using user.save() ??

i tried the following code

if not user.refresh_token or RefreshToken(user.refresh_token).blacklist_after:
        refresh = RefreshToken.for_user(user)
        user.refresh_token = str(refresh)
        user.save()
    else:
        refresh = RefreshToken(user.refresh_token)

    access_token = str(refresh.access_token)

i was expecting that if the refresh token is valid, it will make an access token and if invalid or expired it will create a new refresh token and save it in db. but i got attribute error.d

0

There are 0 best solutions below