I am looking to implement a role based authentication in a Vue/FastApi application. I come from a background of using Web Forms in asp.net and it was fairly simple to hide and show certain forms depending on if the user is an Admin, or a Manager, or Employee etc. Is there a way to do this with Vue/FastApi with JWT?
You will have to split the authentication in two:
Authentication via Vuejs. This is independent from fastapi. The only shared thing will be the fact that upon login, vue will authenticate to fastapi (like a man in the middle that forwards information). Vue will then cache the received JWT token (or whatever token received) and keep it in a session (so that in case of page reload the user does not have to login again). As soon as the user logs out, erase the token from the vue app.
Authentication via FastAPI. Here, you simply authenticate with username and password, get a JWT token as response (or any other token you want) and use such token for the following requests.
Basically, once vue receives user - password, it will authenticate to the fastapi api, get the token and store it somewhere (this depends on how you implement it and on vuejs, I haven't used so I can't say anything).
Connecting to your background, the .net form equivalent would be the vue login form, but I recommend you to first follow some tutorials on vuejs in order to first understand how it works and have a proper understanding of how it works and which are some possibilities for achieving something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With