-
Notifications
You must be signed in to change notification settings - Fork 7
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
3233: Handle session expired in Admin Panel #2906
Conversation
27605a7
to
1a92ffc
Compare
@@ -11,7 +11,7 @@ export const attachSession = async (req: Request, res: Response, next: NextFunct | |||
try { | |||
const sessionId = req.sessionCookie?.id; | |||
if (!sessionId) { | |||
throw new UnauthenticatedError('User not authenticated'); | |||
throw new UnauthenticatedError('Session not found or has expired. Please log in again.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tom suggested a nice idea to which is to use a new http response code to indicate that the session has expired (beyondessential/tupaia-backlog#3233 (comment)). However, I think with the case of session cookie not found, it could be because of some other reasons rather than just the session has expired (eg: someone unauthenticated trying to access the server). So I'm still keeping 401 as the response code here.
@@ -77,9 +79,21 @@ export class TupaiaApi { | |||
}; | |||
} | |||
|
|||
async checkIfAuthorized(response) { | |||
// Unauthorized | |||
if (response.status === 401) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I was wondering whether it is too aggressive to always log out users when there is a 401 but after thinking about it for a while I agree that it makes good sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for handling this. I'm wondering if there is a similar change that needs to happen in psss? If so, would you mind creating a card for it? I don't want to hold up this change and the psss fix is quite a low priority.
merge latest dev into branch for testing
Issue:
https://github.com/beyondessential/tupaia-backlog/issues/3233
https://linear.app/tupaia/issue/MEL-373/
Changes: