Skip to content

Commit

Permalink
fix(oauth): ensure correct redirect page after login
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusted committed Jul 24, 2021
1 parent 9df31a2 commit e0514d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion typescript/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {changeEntriesBehavior} from 'page/modlog';
import {checkRedirect} from './page/account';
import {saveRedirect} from './page/login';
import {changeEntriesBehavior} from './page/modlog';
import {InitalizeColorScheme as initalizeColorScheme} from './color-scheme';
import {ShareButton} from './share-button';
import {BroadcastReady} from './third-party';
Expand Down Expand Up @@ -36,6 +38,12 @@ function pageSpecificFunctions(settings: UserSettings) {
case '/modlog':
changeEntriesBehavior(settings.entriesBehavior);
break;
case '/login':
saveRedirect();
break;
case '/account':
checkRedirect(settings.redirect);
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions typescript/page/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {storeNewSettings} from 'utils/storage';

export function checkRedirect(redirect: string) {
if (redirect) {
storeNewSettings({redirect: ''});
window.location.href = window.location.origin + redirect;
}
}
8 changes: 8 additions & 0 deletions typescript/page/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {storeNewSettings} from 'utils/storage';

export function saveRedirect() {
const redirect = new URLSearchParams(location.search).get('r');
if (redirect) {
storeNewSettings({redirect});
}
}
2 changes: 2 additions & 0 deletions typescript/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export interface UserSettings {
colorScheme: 'dark' | 'light' | 'follow-system';
entriesBehavior: 'hover' | 'click' | 'no-hide';
redirect: string;
}

const DEFAULT_SETTINGS: UserSettings = {
colorScheme: 'follow-system',
entriesBehavior: 'click',
redirect: '',
};

const localStorageKey = 'user-preferences';
Expand Down

0 comments on commit e0514d9

Please sign in to comment.