Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nyeu opened this issue Jan 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@nyeu
Copy link

nyeu commented Jan 9, 2023

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 nyeu added the bug Something isn't working label Jan 9, 2023
@nyeu
Copy link
Author

nyeu commented Jan 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant