pocketbase / js-sdk

PocketBase JavaScript SDK
https://www.npmjs.com/package/pocketbase
MIT License
2.17k stars 127 forks source link

Strange behavior with authStore when working with two pocketbase projects #291

Closed ad-on-is closed 6 months ago

ad-on-is commented 6 months ago

It seems as if the authStore uses the same auth/cookie/whatever across different projects.

Steps to reproduce

Is there any setting I'm missing to prevent this?

ganigeorgiev commented 6 months ago

By default the JS SDK stores uses localStorage and if your both applications operates on the same domain then it is expected to share the same auth state because the localStorage key would be the same.

You can specify a custom unique key by manually initializing the LocalAuthStore:

import PocketBase, { LocalAuthStore } from "pocketbase"

const pb = new PocketBase("http://127.0.0.1:8090", new LocalAuthStore("your_unique_app_key"))

For more details about the auth store you could check https://github.com/pocketbase/js-sdk#auth-store.