-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user is logged out after refreshing #1
Comments
I really, really need to update this with some of the things I've learned since refactoring this from Vue.js. The default way https://github.com/tiangolo/full-stack-fastapi-postgresql is structured is that there is a single The additional challenge is that the Alternatively - albeit not safely - you can simply make the single token approach have an indefinite lifespan, or single-use, or ... basically, you need to think through how secure you want to make the authentication process and go from there. This help? It's not a fix, but it'll take me a little bit to get to updating this repo. |
Hi! thanks for replying! I've seen implementations of the refresh token on the backend side of things with fastapi extensions like https://indominusbyte.github.io/fastapi-jwt-auth/usage/refresh/. In the Oauth implementation in the full stack repo, however, the token lifespan is defined in the The helpers you mention that store the token are in https://github.com/whythawk/full-stack-fastapi-postgresql/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/frontend/utils.ts and are triggered by the If I'm not wrong, a single refresh right after logging in should not expire the token right away. What I don't understand is where is the token expiration date being checked and why am I being logged out after a refresh? |
Assuming your token isn't being erased, review the code for the middleware,
That isn't using the token to reauthenticate, but simply redirecting the user to the login page. Instead you could have something like this:
With an
This way, if a page requires auth you will automatically refresh the user status. You can implement a test for token expiry as follows (I created a utilities folder):
All of these together create a workflow to:
I'm using cookies here for long-term storage of the refresh token. This help? |
Hi! thanks again for replying. There is a method called I see that your |
You can use |
Thanks for your help. I'll play around with this and I'll get back to you. Any reason why you are not using something like https://auth.nuxtjs.org/ ? |
A few reasons ... the first is that most of the stack was already implemented in https://github.com/whythawk/full-stack-fastapi-postgresql and there didn't seem much reason to add yet another third-party library. I'm very uncomfortable with Node's dependency hell. The second is that - while I've gone back and forth over the years on supporting integration of alternative logins (e.g. Google/Facebook) - these days I want to ensure that there is no risk of leakage to third-party trackers. Auth is the most important part of securing the privacy and integrity of users. It's also not that difficult, so I kept it this way. If you find it easier to slot something else in, go for it. |
Hey thanks for this! I'm using https://github.com/whythawk/full-stack-fastapi-postgresql and I'm getting problems with the authentication flow
After logging in, I get redirected to the
/dashboard
. At this moment if I refresh the page I get logged out. Why is this? I was expecting to stay logged in.The text was updated successfully, but these errors were encountered: