summaryrefslogtreecommitdiff
path: root/web/source/settings/redux
diff options
context:
space:
mode:
Diffstat (limited to 'web/source/settings/redux')
-rw-r--r--web/source/settings/redux/login.ts (renamed from web/source/settings/redux/oauth.ts)52
-rw-r--r--web/source/settings/redux/store.ts10
2 files changed, 21 insertions, 41 deletions
diff --git a/web/source/settings/redux/oauth.ts b/web/source/settings/redux/login.ts
index 1d6bf9bb1..2ba06dfff 100644
--- a/web/source/settings/redux/oauth.ts
+++ b/web/source/settings/redux/login.ts
@@ -18,33 +18,11 @@
*/
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
+import { OAuthApp, OAuthAccessToken } from "../lib/types/oauth";
-/**
- * OAuthToken represents a response
- * to an OAuth token request.
- */
-export interface OAuthToken {
- /**
- * Most likely to be 'Bearer'
- * but may be something else.
- */
- token_type: string;
- /**
- * The actual token. Can be passed in to
- * authenticate further requests using the
- * Authorization header and the token type.
- */
- access_token: string;
-}
-
-export interface OAuthApp {
- client_id: string;
- client_secret: string;
-}
-
-export interface OAuthState {
+export interface LoginState {
instanceUrl?: string;
- loginState: "none" | "callback" | "login" | "logout";
+ current: "none" | "awaitingcallback" | "loggedin" | "loggedout";
expectingRedirect: boolean;
/**
* Token stored in easy-to-use format.
@@ -55,29 +33,31 @@ export interface OAuthState {
app?: OAuthApp;
}
-const initialState: OAuthState = {
- loginState: 'none',
+const initialState: LoginState = {
+ current: 'none',
expectingRedirect: false,
};
-export const oauthSlice = createSlice({
- name: "oauth",
+export const loginSlice = createSlice({
+ name: "login",
initialState: initialState,
reducers: {
- authorize: (_state, action: PayloadAction<OAuthState>) => {
+ authorize: (_state, action: PayloadAction<LoginState>) => {
// Overrides state with payload.
return action.payload;
},
- setToken: (state, action: PayloadAction<OAuthToken>) => {
- // Mark us as logged in by storing token.
+ setToken: (state, action: PayloadAction<OAuthAccessToken>) => {
+ // Mark us as logged
+ // in by storing token.
state.token = `${action.payload.token_type} ${action.payload.access_token}`;
- state.loginState = "login";
+ state.current = "loggedin";
},
remove: (state) => {
- // Mark us as logged out by clearing auth.
+ // Mark us as logged
+ // out by clearing auth.
delete state.token;
delete state.app;
- state.loginState = "logout";
+ state.current = "loggedout";
}
}
});
@@ -86,4 +66,4 @@ export const {
authorize,
setToken,
remove,
-} = oauthSlice.actions;
+} = loginSlice.actions;
diff --git a/web/source/settings/redux/store.ts b/web/source/settings/redux/store.ts
index 0c1285187..076f5f88d 100644
--- a/web/source/settings/redux/store.ts
+++ b/web/source/settings/redux/store.ts
@@ -30,19 +30,19 @@ import {
REGISTER,
} from "redux-persist";
-import { oauthSlice } from "./oauth";
+import { loginSlice } from "./login";
import { gtsApi } from "../lib/query/gts-api";
const combinedReducers = combineReducers({
[gtsApi.reducerPath]: gtsApi.reducer,
- oauth: oauthSlice.reducer,
+ login: loginSlice.reducer,
});
const persistedReducer = persistReducer({
key: "gotosocial-settings",
storage: require("redux-persist/lib/storage").default,
stateReconciler: require("redux-persist/lib/stateReconciler/autoMergeLevel1").default,
- whitelist: ["oauth"],
+ whitelist: ["login"],
migrate: async (state) => {
if (state == undefined) {
return state;
@@ -51,8 +51,8 @@ const persistedReducer = persistReducer({
// This is a cheeky workaround for
// redux-persist being a stickler.
let anyState = state as any;
- if (anyState?.oauth != undefined) {
- anyState.oauth.expectingRedirect = false;
+ if (anyState?.login != undefined) {
+ anyState.login.expectingRedirect = false;
}
return anyState;