Consider tracker logged out if token is expired
Server returns logged in state for a tracker even while the token has expired
This commit is contained in:
@@ -24,7 +24,7 @@ import Button from '@mui/material/Button';
|
|||||||
import { PasswordTextField } from '@/components/atoms/PasswordTextField.tsx';
|
import { PasswordTextField } from '@/components/atoms/PasswordTextField.tsx';
|
||||||
import { makeToast } from '@/components/util/Toast.tsx';
|
import { makeToast } from '@/components/util/Toast.tsx';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { TBaseTracker } from '@/lib/data/Trackers.ts';
|
import { TBaseTracker, Trackers } from '@/lib/data/Trackers.ts';
|
||||||
|
|
||||||
export const SettingsTrackerCard = ({ tracker }: { tracker: TBaseTracker }) => {
|
export const SettingsTrackerCard = ({ tracker }: { tracker: TBaseTracker }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -93,7 +93,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TBaseTracker }) => {
|
|||||||
/>
|
/>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
<ListItemText primary={tracker.name} />
|
<ListItemText primary={tracker.name} />
|
||||||
{tracker.isLoggedIn && (
|
{Trackers.isLoggedIn(tracker) && (
|
||||||
<ListItemSecondaryAction>
|
<ListItemSecondaryAction>
|
||||||
<Chip label={t('global.label.logged_in')} color="success" />
|
<Chip label={t('global.label.logged_in')} color="success" />
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
@@ -101,12 +101,12 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TBaseTracker }) => {
|
|||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
<Dialog
|
<Dialog
|
||||||
{...bindDialog(popupState)}
|
{...bindDialog(popupState)}
|
||||||
open={(tracker.isLoggedIn || !tracker.authUrl) && popupState.isOpen}
|
open={(Trackers.isLoggedIn(tracker) || !tracker.authUrl) && popupState.isOpen}
|
||||||
disableRestoreFocus
|
disableRestoreFocus
|
||||||
>
|
>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{t(
|
{t(
|
||||||
tracker.isLoggedIn
|
Trackers.isLoggedIn(tracker)
|
||||||
? 'tracking.settings.dialog.title.log_out'
|
? 'tracking.settings.dialog.title.log_out'
|
||||||
: 'tracking.settings.dialog.title.log_in',
|
: 'tracking.settings.dialog.title.log_in',
|
||||||
{ name: tracker.name },
|
{ name: tracker.name },
|
||||||
@@ -142,9 +142,9 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TBaseTracker }) => {
|
|||||||
!tracker.isLoggedIn &&
|
!tracker.isLoggedIn &&
|
||||||
(isCredentialLoginInProgress || !username.length || !password.length)
|
(isCredentialLoginInProgress || !username.length || !password.length)
|
||||||
}
|
}
|
||||||
onClick={() => (tracker.isLoggedIn ? handleLogout() : handleLogin())}
|
onClick={() => (Trackers.isLoggedIn(tracker) ? handleLogout() : handleLogin())}
|
||||||
>
|
>
|
||||||
{t(tracker.isLoggedIn ? 'global.button.log_out' : 'global.button.log_in')}
|
{t(Trackers.isLoggedIn(tracker) ? 'global.button.log_out' : 'global.button.log_in')}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export type TrackerManga = TrackerSearchQuery['searchTracker']['trackSearches'][
|
|||||||
|
|
||||||
export type TBaseTracker = GetTrackersQuery['trackers']['nodes'][number];
|
export type TBaseTracker = GetTrackersQuery['trackers']['nodes'][number];
|
||||||
|
|
||||||
type LoggedInInfo = Pick<TrackerType, 'isLoggedIn'>;
|
type LoggedInInfo = Pick<TrackerType, 'isLoggedIn' | 'isTokenExpired'>;
|
||||||
|
|
||||||
type TrackRecordTrackerInfo = { tracker: Partial<TrackRecordType['tracker']> };
|
type TrackRecordTrackerInfo = { tracker: Partial<TrackRecordType['tracker']> };
|
||||||
|
|
||||||
@@ -43,8 +43,12 @@ export class Trackers {
|
|||||||
return this.isUnsetDate(date) ? undefined : date;
|
return this.isUnsetDate(date) ? undefined : date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static isLoggedIn<Tracker extends LoggedInInfo>(tracker: Tracker): boolean {
|
||||||
|
return tracker.isLoggedIn && !tracker.isTokenExpired;
|
||||||
|
}
|
||||||
|
|
||||||
static getLoggedIn<Tracker extends LoggedInInfo>(trackers: Tracker[]): Tracker[] {
|
static getLoggedIn<Tracker extends LoggedInInfo>(trackers: Tracker[]): Tracker[] {
|
||||||
return trackers.filter((tracker) => tracker.isLoggedIn);
|
return trackers.filter(this.isLoggedIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getTrackers<TrackRecord extends TrackRecordTrackerInfo>(
|
static getTrackers<TrackRecord extends TrackRecordTrackerInfo>(
|
||||||
|
|||||||
Reference in New Issue
Block a user