diff options
| author | 2025-03-17 15:06:17 +0100 | |
|---|---|---|
| committer | 2025-03-17 14:06:17 +0000 | |
| commit | d5847e2d2b68a1eb41d43be170cd4ddff9003cff (patch) | |
| tree | 7352e79110b081eb72d483358f5c07c8d34c29ff /web/source/settings/redux | |
| parent | [feature/frontend] Add visibility icon for posts (#3908) (diff) | |
| download | gotosocial-d5847e2d2b68a1eb41d43be170cd4ddff9003cff.tar.xz | |
[feature] Application creation + management via API + settings panel (#3906)
* [feature] Application creation + management via API + settings panel
* fix docs links
* add errnorows test
* use known application as shorter
* add comment about side effects
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.ts | 10 |
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; |
