Closed glennposadas closed 1 year ago
Hi @glennposadas. Thanks for opening the issue.
The error message you provided states that the token signature is invalid, which is not related to the token expiration time.
If your environments have different app keys/secrets on Stream Dashboard (and I assume this is true), then you need to recreate the client every time you change the environment so the client picks up the correct token.
Hope this helps.
Best wishes, Alexey
Hi, @testableapple . Thanks for replying. But can you help me with how to do what you suggested. Could you please help me and point it to me? Thanks!
Hi @glennposadas, just follow the docs here
/// for sake of simplicity we are extending ChatClient and add a static var `shared`
extension ChatClient {
static var shared: ChatClient!
}
/// you can grab your API Key from https://getstream.io/dashboard/
let config = ChatClientConfig(apiKey: .init("<# Your API Key Here #>"))
/// create an instance of ChatClient and share it using the singleton
ChatClient.shared = ChatClient(config: config) { completion in
/// This closure will be called when the token is expired
/// You don't need to provide a closure if you're not using expired tokens
/// You need to fetch a valid token for your Stream user here
YourNetworkLayer.fetchUserToken { token in
/// and call the completion closure with the token
completion(.success(token))
}
}
You'll need to use different configs for each environment and update ChatClient.shared
as soon as you switch the environment.
Best, Alexey
Thank you, @testableapple! Have you had a chance before wherein you read a code and you get surprised like: 'oh I wrote this?'? Anyway, yeah, it should be fixed now. Thanks again!
What did you do?
We have multiple environments, therefore multiple Stream projects. Two of which are sometimes giving the said error. Uninstalling and reinstalling aren't helping.
What did you expect to happen?
Switching between environments should not cause any issues.
What happened instead?
This error shows up in the logs:
Do tokens have some kind of default expiration time? We are not adding an expiration time explicitly.
GetStream Environment
GetStream Chat version: 4.32 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 15.2+ Swift version:5.7.2 Xcode version:14.2 Device:Real iPhones
Additional context
I am saving the token from the server to my defaults, and reuse it. I am not sure if this causes the issue, but as mentioned, this should be resolved by simply reinstalling but no.