-
Notifications
You must be signed in to change notification settings - Fork 39
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
Define onTokenExpired event #25
Comments
Hi, @jfoliveira! |
Correct.
That could be a starting point. Example, pseudo code from a user consuming Devopness SDK-JS and logging the event to the console: import { DevopnessApiClient } from '@devopness/sdk-js'
// 1) consumer initialize DevopnessApiClient instance
const devopnessApi = new DevopnessApiClient();
// 2) consumer defines its own event handler for the`onTokenExpired` event:
public doThisWhenDevopnessTriggerTokenExpiredEvent(): void {
console.log('Devopness `tokenExpired` event has been triggered.');
}
// 3) consumer tells client instance to invoke a custom method when the event is triggered:
devopnessApi.onTokenExpired = doThisWhenDevopnessTriggerTokenExpiredEvent;
// any other code interacting with Devopness SDK:
const userTokens = await devopnessApi.users.loginUser(...) Then, on the SDK itself, we could check if the consumer defined an event handler and - if so - we trigger the externally defined method: public onTokenExpired: () => void;
public tokenExpired(): void {
if (this.onTokenExpired) {
this.onTokenExpired();
}
} Let us know if you have further questions. |
👋 Hi there!
|
👋 Hi there!
|
👋 Hi there!
|
❌ This issue was closed because it has been open and inactive for a month. |
👋 Hi there!
|
❌ This issue was closed because it has been open and inactive for a month. |
Is your feature request related to a problem? Please describe.
Currently SDK users need to implement a token refresh process if they want to keep a user logged in. This works fine, but could be easier for SDK users when a token expired, as token expiration HTTP 401 may require some logic to be differentiated from regular HTTP 401 status code.
Describe the solution you'd like
Describe alternatives you've considered
Check for HTTP status code equals 401 and send a token refresh request.
Pseudo-code, yet to be tested:
Additional context
The responsibility on making the decision of refreshing a token or not doesn't change. It'll still be up to the SDK consumer to decide what to do.
We just want to assume the logic that will check the
HTTP 401 Unauthorized
response to tell which ones are related to token expiration and notify the client app.The text was updated successfully, but these errors were encountered: