Skip to content

Commit

Permalink
feat: add logout event hook (pinterest#1104)
Browse files Browse the repository at this point in the history
* feat: add logout event hook

* Make sure refresh banner logs out user
  • Loading branch information
czgu authored and aidenprice committed Jan 3, 2024
1 parent e07c3ce commit 6413af6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.15.0",
"version": "3.15.1",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions querybook/server/app/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def load_auth():


def logout():
global auth
has_logout = hasattr(auth, "on_logout_user")
if has_logout:
auth.on_logout_user()

logout_user()


Expand Down
7 changes: 4 additions & 3 deletions querybook/server/lib/event_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def log(

def log_api_request(self, route: str, method: str, params: dict):
try:
self.logger.log_api_request(
uid=current_user.id, route=route, method=method, params=params
)
if current_user.is_authenticated:
self.logger.log_api_request(
uid=current_user.id, route=route, method=method, params=params
)
except Exception as e:
LOG.error(e, exc_info=True)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, { useCallback } from 'react';

import { useGlobalState } from 'hooks/redux/useGlobalState';
import { UserResource } from 'resource/user';
import { Title } from 'ui/Title/Title';

export const SessionExpirationNotice: React.FC = () => {
const [sessionExpired] = useGlobalState('sessionExpired', false);
const refreshPage = useCallback(() => window.location.reload(), []);
const refreshPage = useCallback(() => {
// Try to logout in case it wasn't shown correctly
UserResource.logout().finally(() => {
window.location.reload();
});
}, []);
return sessionExpired ? (
<div
className="flex-center"
Expand Down

0 comments on commit 6413af6

Please sign in to comment.