Zero Sync Authentication

Zero Docs
The official documentation for Zero by Rocicorp.
JWT | Better Auth
Authenticate users with JWT tokens in services that can't use the session
Solution:
If anyone is wandering how to get better auth with nextjs. Link : https://discord.com/channels/830183651022471199/1361694110972645597/1361898149475778732...
Jump to solution
14 Replies
bekacru
bekacru2w ago
set ZERO_AUTH_JWKS_URL https://your-site.com/api/auth/jwks and in the token you can fetch for the jwt token from "/token" endpoint
Tenuka
TenukaOP2w ago
That gives me the error "kind":"AuthInvalidated" │,"message":"Failed to decode auth token: JWTClaimValidationFailed: unexpected "sub" claim value"
kenpachi
kenpachi2w ago
Any luck? I am twisting my hair here thinking of with rolling my own session based/jwt
Tenuka
TenukaOP2w ago
No nothing yet I'm also suck of this err
bekacru
bekacru2w ago
can you guys try this version pnpm i https://pkg.pr.new/better-auth/better-auth@2194 and report back
kenpachi
kenpachi2w ago
Ok it worked with me, zero can can decode my jwt token through ZERO_AUTH_JWKS_URL='http://localhost:3000/api/auth/jwks' what i did was I removed the ZERO_AUTH_SECERT= and also i ended the cache server dev:cache rebuilt it with npm rebuild and it worked. i have no clue what made it work but yeah whenever i was runing into issues i just closed my cache dev and rebuilt and reran it
bekacru
bekacru2w ago
it worked with the version I sent above?
kenpachi
kenpachi2w ago
no but i am on the latest version of better-auth I think the there is a conflict between the better auth secert and zero auth secert because whenever i add it i get the same error message
Tenuka
TenukaOP2w ago
Event If I've used ZERO_AUTH_JWKS_URL and zero decode the auth it gives a claim error,
bekacru
bekacru2w ago
have you treid the patch version?
Tenuka
TenukaOP2w ago
Yes Still worker=syncer pid=12680 errorKind=AuthInvalidated Sending error on WebSocket {"kind":"AuthInvalidated","message":"Failed to decode auth token: JWTClaimValidationFailed: unexpected "sub" claim value"} comming from zero cache
kenpachi
kenpachi2w ago
How are you getting the jwt from authClient.token without passing the header options such as cookie ? are you sure you are getting a jwt token?
const token = await authClient.token({
header: {
Cookie: `better-auth.session_token=${getCookie("better-auth.session_token")}`,
}
})
const token = await authClient.token({
header: {
Cookie: `better-auth.session_token=${getCookie("better-auth.session_token")}`,
}
})
Tenuka
TenukaOP2w ago
authClient gets the cookies and headers automaticly so I don't need to spacify manually. also I've tried to get the token manually with authclient.token and It gave me a correct token
Solution
Tenuka
Tenuka5d ago
If anyone is wandering how to get better auth with nextjs. Link : https://discord.com/channels/830183651022471199/1361694110972645597/1361898149475778732

Did you find this page helpful?