mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 18:24:20 +00:00
fix(user_dashboard.tsx): add token expiry logic to user dashboard
if token expired redirect to `/sso/key/generate` for login
This commit is contained in:
parent
dc9b058dbd
commit
be3276200b
1 changed files with 40 additions and 2 deletions
|
@ -311,8 +311,46 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
|
|||
window.location.href = url;
|
||||
|
||||
return null;
|
||||
} else if (accessToken == null) {
|
||||
return null;
|
||||
} else {
|
||||
// Check if token is expired
|
||||
try {
|
||||
const decoded = jwtDecode(token) as { [key: string]: any };
|
||||
const expTime = decoded.exp;
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
|
||||
if (expTime && currentTime >= expTime) {
|
||||
console.log("Token expired, redirecting to login");
|
||||
|
||||
// Clear token cookies
|
||||
clearTokenCookies();
|
||||
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/sso/key/generate`
|
||||
: `/sso/key/generate`;
|
||||
|
||||
console.log("Full URL for expired token:", url);
|
||||
window.location.href = url;
|
||||
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error decoding token:", error);
|
||||
// If there's an error decoding the token, consider it invalid
|
||||
clearTokenCookies();
|
||||
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/sso/key/generate`
|
||||
: `/sso/key/generate`;
|
||||
|
||||
console.log("Full URL after token decode error:", url);
|
||||
window.location.href = url;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (userID == null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue