access token expiration
# support
t
Hi everyone, our team had some concerns about how long an idle user can stay logged in to our EHR. The access token appears to last 1 hour and that's not configurable. Is there a way to change the access token expiration, so we can log a user off after a shorter idle period than an hour?
a
Oh, wow. It looks like everyone is asking the same question all of a sudden. I wrote about the very same challenge around this in a recent post here: https://discord.com/channels/905144809105260605/1332907731962826834) ...but no solution yet! 😦 And someone else just posted about it here: https://discord.com/channels/905144809105260605/1308564422096064604/1308564422096064604 Anyhow... you might take a look at this, though... [⁠support⁠Increase active session time](https://discord.com/channels/905144809105260605/1308564422096064604/1308564422096064604) And if you do check it out, and if it works... please, please let me know how you did it, so I can give it a go also. 🙂
Well... i don't know if this is going to work, but this is what I'm going to try: // Add useEffect to your existing imports import { Suspense, useState, useEffect } from 'react'; // Add this effect right after your existing useEffect hooks export function App(): JSX.Element | null { const medplum = useMedplum(); // Add token refresh effect useEffect(() => { if (!medplum) return; // Refresh token every 45 minutes (giving 15 min buffer before 1 hour expiration) const refreshInterval = setInterval(() => { medplum.refreshIfExpired(900); // 900 seconds (15 minutes) grace period }, 45 * 60 * 1000); return () => clearInterval(refreshInterval); }, [medplum]); // ... rest of your existing App component code }
r
Are you using the TS SDK on the client? Refresh functionality is baked into the client and may solve the logout issue. Here's some documentation of the Lifecycle Events https://www.medplum.com/docs/react/lifecycle-events As well as refreshIfExpired method https://www.medplum.com/docs/sdk/core.medplumclient.refreshifexpired
t
Appreciate the responses!
r
@Tom Wei - new functionality on this front was released - here's the documentation! https://www.medplum.com/docs/auth/token-lifetime
181 Views