how to use `auth.api` on other servers
I have currently made a single auth server and admin panel on users.xyz.com and using that server with
authClient
while using its URL (backend). This works fine for requests made from frontend directly directly to the auth backend.
But when we need to authenticate the user on our backend (different from auth server), then how should we do it.7 Replies
One way I am thinking of is to use the REST endpoints.
Like for
auth.api.getSession
we could use this.
I am correct in my approach and is there a better and more typesafe way to do this
You can use jwt plugin
https://www.better-auth.com/docs/plugins/jwt
JWT | Better Auth
Authenticate users with JWT tokens in services that can't use the session
Bearer Token Authentication | Better Auth
Authenticate API requests using Bearer tokens instead of browser cookies
Could you also some advice on using one instance of better auth as the main auth server and then using it in multipple apps.
like if my auth server is at users.xyz.com then how to use it effectively in app1.xyz.cm and so on.
Is this what I should be referring to https://www.better-auth.com/docs/concepts/cookies#cross-subdomain-cookies
But it seems a little vague as to what exactly the trustedOrigins does I had to configure the hook myself in the end to have it work in localhost atleasr
If my question is not please let me know
Cookies | Better Auth
Learn how cookies are used in Better Auth.