supabase-community / gotrue-swift

A Swift client library for GoTrue.
MIT License
36 stars 31 forks source link

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

Open nyeu opened 1 year ago

nyeu commented 1 year ago

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

nyeu commented 1 year ago

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