Current refresh token or null if not authenticated
// Before attempting token refresh
const refreshToken = getRefreshToken();
if (refreshToken) {
// Proceed with token refresh
} else {
// Cannot refresh, require re-authentication
}
export function getRefreshToken(): string | null {
const refreshToken = getRefreshTokenState();
if (refreshToken) return refreshToken;
// If not in memory, try loading from encrypted storage
const tokens = tokenStorage.loadTokens();
if (tokens) {
// Update memory state with loaded tokens
setAccessTokenState(tokens.accessToken);
setRefreshTokenState(tokens.refreshToken);
setTokenExpiryState(tokens.expiresAt);
return tokens.refreshToken;
}
return null;
}
Gets the current refresh token
Retrieves the refresh token using a two-tier strategy:
The refresh token is critical for maintaining long-term authentication by obtaining new access tokens when they expire.