gotrue-swift icon indicating copy to clipboard operation
gotrue-swift copied to clipboard

json: cannot unmarshal number into Go struct field GoTrueClaims.exp of type int64

Open nyeu opened this issue 2 years ago • 1 comments

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]

nyeu avatar Jan 09 '23 12:01 nyeu

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))

nyeu avatar Jan 09 '23 13:01 nyeu