JS SDK - How to detect an expired token? #4998
Unanswered
VictorioBerra
asked this question in
Q&A
Replies: 1 comment
-
One idea that I have not tested, would be to export 2 different pocketbase clients from the plugin. anonymousPocketbase and authenticatedPocketbase. One would be configured with a beforeSend hook to trip if isValid is false and the other would not check for auth at all. Bad idea? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a fully-client side Nuxt3 app, I am using the following hook for my JS SDK in my pocketbase.ts Nuxt 3 Plugin:
Essentially what I have found is that Pocketbase will not give me a 401 or 403 during a POST to one of my collections for example when the token is expired. It will give a 400. I think this is probably due to my API rules acting as filters? For example my create rule:
The error would be
DrySubmit create rule failure: sql: no rows in result set
Is there a better way to do what I am trying to do? I set my token expiration to 10 seconds just to test this out and my hook does work but it feels pretty hacky. I do realize some requests it is OK that they are unauthenticated. It would be nice to have some way to flag the request as requires auth, and then do my isValid checks and redirects there.
Beta Was this translation helpful? Give feedback.
All reactions