mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
- Added Site settings > Authentication section - Create/edit/delete your custom oauth2 configurations - Login or signup with oauth2
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { Action } from 'redux';
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
|
import { IOAuthJSON } from '../../interfaces/IOAuth';
|
|
|
|
import { State } from '../../reducers/rootReducer';
|
|
|
|
export const OAUTHS_REQUEST_START = 'OAUTHS_REQUEST_START';
|
|
interface OAuthsRequestStartAction {
|
|
type: typeof OAUTHS_REQUEST_START;
|
|
}
|
|
|
|
export const OAUTHS_REQUEST_SUCCESS = 'OAUTHS_REQUEST_SUCCESS';
|
|
interface OAuthsRequestSuccessAction {
|
|
type: typeof OAUTHS_REQUEST_SUCCESS;
|
|
oAuths: Array<IOAuthJSON>;
|
|
}
|
|
|
|
export const OAUTHS_REQUEST_FAILURE = 'OAUTHS_REQUEST_FAILURE';
|
|
interface OAuthsRequestFailureAction {
|
|
type: typeof OAUTHS_REQUEST_FAILURE;
|
|
error: string;
|
|
}
|
|
|
|
export type OAuthsRequestActionTypes =
|
|
OAuthsRequestStartAction |
|
|
OAuthsRequestSuccessAction |
|
|
OAuthsRequestFailureAction;
|
|
|
|
|
|
const oAuthsRequestStart = (): OAuthsRequestActionTypes => ({
|
|
type: OAUTHS_REQUEST_START,
|
|
});
|
|
|
|
const oAuthsRequestSuccess = (
|
|
oAuths: Array<IOAuthJSON>
|
|
): OAuthsRequestActionTypes => ({
|
|
type: OAUTHS_REQUEST_SUCCESS,
|
|
oAuths,
|
|
});
|
|
|
|
const oAuthsRequestFailure = (error: string): OAuthsRequestActionTypes => ({
|
|
type: OAUTHS_REQUEST_FAILURE,
|
|
error,
|
|
});
|
|
|
|
export const requestOAuths = (): ThunkAction<void, State, null, Action<string>> => (
|
|
async (dispatch) => {
|
|
dispatch(oAuthsRequestStart());
|
|
|
|
try {
|
|
const response = await fetch('/o_auths');
|
|
const json = await response.json();
|
|
|
|
dispatch(oAuthsRequestSuccess(json));
|
|
} catch (e) {
|
|
dispatch(oAuthsRequestFailure(e));
|
|
}
|
|
}
|
|
) |