store Auth Token in browser
With the @mnfst/sdk, is it possible to store the Auth Token in the browser. So the User doesn't always has to relogin with username and password.
7 Replies
Hello @Waahnsinn,
I updated the @mnfst/sdk so you can do it. From version 1.2.2 you can now:
Thank you for your message!
Maybe we could also log in using just the token? Currently, with Astro I have to log in the user every time they are taken to another page. I made a small wrapper for this, but it would certainly be easier to handle it directly via the SDK
Hello @fedehusk when you use
manifest.login()
, the SDK automatically sets the token in the Authorization headers for all following requests. If you have to login at each new page, it probably means that you are getting a new SDK instance each time. Do you initialize the SDK (const manifest = new Manifest()
) in a service/shared singleton file ?Hi, sorry for the late reply! I didn't actually put it in a singleton, so it didn't work. However, since I don't want to pass data between different users, I need to use a different solution. Do you think something like this would be a good idea?
@fedehusk are you using Astro as SSG ? I do not really understand the need for authentication. What is DBsession ?
Yup, Astro serves as SSG. I want my user to be logged while using the website/app.
When I use a singleton, Manifests is running on one instace for the app, but I want it to be one instance for user, so I can make operations as them. That's why I use DBsession wrapper
@fedehusk I think there is a misconception of build time and run time. When building, Astro (or other framework) fetches the dynamic content to generate static pages. At this moment you should not need to log if your data is public anyway, you should have public read policies https://manifest.build/docs/access on your entities.
However, in your runtime JS (the one that is going to be bundled and executed on the client), using a service where you only instantiate once Manifest SDK
const manifest = new Manifest()
will result in having one instance/session per client or user so API requests should not return 403 errors once loggedAccess Policies & Authorization | Manifest Docs
Learn how to implement API policies to restrict resource access for CRUD operations and endpoints.