* Refresh the session * * This method refreshes the session token using the client token.
()
| 432 | * This method refreshes the session token using the client token. |
| 433 | */ |
| 434 | private async refreshSession(): Promise<void> { |
| 435 | if (!this.credentials) { |
| 436 | this.log("[auth] Cannot refresh session: missing credentials") |
| 437 | return |
| 438 | } |
| 439 | |
| 440 | try { |
| 441 | const previousState = this.state |
| 442 | this.sessionToken = await this.clerkCreateSessionToken() |
| 443 | |
| 444 | if (previousState !== "active-session") { |
| 445 | this.changeState("active-session") |
| 446 | this.fetchUserInfo() |
| 447 | } else { |
| 448 | this.state = "active-session" |
| 449 | } |
| 450 | } catch (error) { |
| 451 | if (error instanceof InvalidClientTokenError) { |
| 452 | this.log("[auth] Invalid/Expired client token: clearing credentials") |
| 453 | this.clearCredentials() |
| 454 | } else if (this.isFirstRefreshAttempt && this.state === "attempting-session") { |
| 455 | this.isFirstRefreshAttempt = false |
| 456 | this.transitionToInactiveSession() |
| 457 | } |
| 458 | this.log("[auth] Failed to refresh session", error) |
| 459 | throw error |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | private async fetchUserInfo(): Promise<void> { |
| 464 | if (!this.credentials) { |
no test coverage detected