Skip to content

Commit

Permalink
#130 Logout RMP on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
thekingofcity committed Sep 28, 2024
1 parent f118771 commit 4ccb1ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/menu/account-view/account-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {
import { RmgDebouncedInput } from '@railmapgen/rmg-components';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { MdDriveFileRenameOutline, MdLogout, MdPassword } from 'react-icons/md';
import { useRootDispatch, useRootSelector } from '../../../redux';
import { logout, setToken, updateName } from '../../../redux/account/account-slice';
import { API_ENDPOINT, API_URL } from '../../../util/constants';
import { notifyRMPTokenUpdate } from '../../../util/local-storage-save';
import { apiFetch } from '../../../util/utils';
import { MdDriveFileRenameOutline, MdLogout, MdPassword } from 'react-icons/md';

const style: SystemStyleObject = {
alignItems: 'center',
Expand Down Expand Up @@ -52,6 +53,7 @@ const AccountInfo = () => {
body: JSON.stringify({ refreshToken }),
});
dispatch(logout());
notifyRMPTokenUpdate();
};

return (
Expand Down
14 changes: 3 additions & 11 deletions src/util/local-storage-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const onSaveUpdate = async (currentSaveId: number, token: string, refreshToken:
};

// This should triggger RMP to refetch subscription info.
export const notifyRMPTokenUpdate = (token: string) => {
export const notifyRMPTokenUpdate = (token?: string) => {
channel.postMessage({
type: SaveManagerEventType.TOKEN_REQUEST,
token: token,
Expand All @@ -113,11 +113,7 @@ export const registerOnTokenRequest = (store: ReturnType<typeof createStore>) =>

const { isLoggedIn, token, refreshToken } = store.getState().account;
if (!isLoggedIn || !token || !refreshToken) {
channel.postMessage({
type: SaveManagerEventType.TOKEN_REQUEST,
token: undefined,
from: 'rmt',
} as SaveManagerEvent);
notifyRMPTokenUpdate();
return;
}

Expand All @@ -129,11 +125,7 @@ export const registerOnTokenRequest = (store: ReturnType<typeof createStore>) =>
refreshToken: refreshTokenAfterFetch,
} = store.getState().account;
if (!isLoggedInAfterFetch || !tokenAfterFetch || !refreshTokenAfterFetch) {
channel.postMessage({
type: SaveManagerEventType.TOKEN_REQUEST,
token: undefined,
from: 'rmt',
} as SaveManagerEvent);
notifyRMPTokenUpdate();
return;
}

Expand Down

0 comments on commit 4ccb1ca

Please sign in to comment.