gotrue-swift
gotrue-swift copied to clipboard
json: cannot unmarshal number into Go struct field GoTrueClaims.exp of type int64
Bug report
I have created a JWT token and when I use it in supabase client
with the session it throws an error. I tracked down the issue and its thrown in your library GoTrue, on setSession(accessToken: String, refreshToken: String)
.
The issue reported is the following:
invalid JWT: unable to parse or verify signature, json: cannot unmarshal number 1673267144.2241859 into Go struct field GoTrueClaims.exp of type int64
I am creating the token like the following:
let jwtSigner = JWTSigner.hs256(key: pKey)
let exp = Date(timeIntervalSinceNow: 3600)
let header = Header(kid: SupabaseService.SupabaseAnoKey)
let claims = SupabaseClaims(userID: userID,
exp: exp)
var supJWT = JWT(header: header, claims: claims)
To Reproduce
Create a JWT token.
Add the token to the current supabase session try await client.auth.setSession(accessToken: token, refreshToken: refreshToken)
Get the error.
invalid JWT: unable to parse or verify signature, json: cannot unmarshal number 1673267144.2241859 into Go struct field GoTrueClaims.exp of type int64
Expected behavior
It should let me do the request since the token is valid.
System information
- OS: [e.g. macOS, Windows]: macOS Monterey (12.5.1 (21G83))
- Version of supabase-js: [e.g. 6.0.2]: Latest (points to
master
) - Version of Node.js: [e.g. 10.10.0]
Here's the workaround to fix it:
let expDouble = Date(timeIntervalSinceNow: 3600)
let d: Double = expDouble.timeIntervalSince1970
let i = Int(d)
let exp = Date(timeIntervalSinceNow: Double(i))