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

JWT Token expires fast, and new one is not provided #50

Closed
semirteskeredzic opened this issue May 15, 2024 · 1 comment
Closed

JWT Token expires fast, and new one is not provided #50

semirteskeredzic opened this issue May 15, 2024 · 1 comment

Comments

@semirteskeredzic
Copy link

semirteskeredzic commented May 15, 2024

I am using the token in the Authorization header when sending request to my API endpoint.

Here is how I'm fetching data with async function and using lastActiveToken from clerk.session:

@ObservedObject private var clerk = Clerk.shared

Task {
  do {
    isLoading = true
    defer { isLoading = false }
    try await locationData.fetchLocations(token: clerk.session?.lastActiveToken?.jwt ?? "")
  } catch {
     print(error)
}

This token expires really fast while the app is running (cca 1 minute) and it doesn't get any new one.

When I print the session the exp of the session is expiring a couple of days from now (printed on 2024-05-15):

status: ClerkSDK.SessionStatus.active, expireAt: 2024-05-21 06:43:37 +0000, abandonAt: 2024-06-13 06:43:37 +0000, lastActiveAt: 2024-05-14 06:43:37 +0000

On my server I am logging returned JSON object from response:

[iostest] [2024-05-15 08:33:29] decoded {
[iostest] [2024-05-15 08:33:29]   exp: 1715762069,
[iostest] [2024-05-15 08:33:29]   iat: 1715762009,
[iostest] [2024-05-15 08:33:29]   iss: 'https://x.clerk.accounts.dev',
[iostest] [2024-05-15 08:33:29]   nbf: 1715761999,
[iostest] [2024-05-15 08:33:29]   sid: 'sess_x',
[iostest] [2024-05-15 08:33:29]   sub: 'user_x'
[iostest] [2024-05-15 08:33:29] }
    • used x to redact data
@semirteskeredzic semirteskeredzic changed the title JWT Token expires too fast JWT Token expires fast, and new one is not provided May 15, 2024
@semirteskeredzic
Copy link
Author

After going through the API documentation, I've figured out that I've been using wrong jwt. The correct one is:
clerk.session?.getToken()?.jwt
This is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant