Skip to content

Commit

Permalink
Merge pull request #3742 from marmelab/discriminated-union-type-for-a…
Browse files Browse the repository at this point in the history
…uth-action

[RFR] Discriminated union type for auth action
  • Loading branch information
djhi authored Sep 30, 2019
2 parents a7d2016 + 05739e7 commit bd78647
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 12 additions & 7 deletions packages/ra-core/src/auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { AuthActionType } from '../types';

export type UserCheck = (
payload: object,
pathName: string,
routeParams?: object
) => void;

export const AUTH_LOGIN: AuthActionType = 'AUTH_LOGIN';
export const AUTH_CHECK: AuthActionType = 'AUTH_CHECK';
export const AUTH_ERROR: AuthActionType = 'AUTH_ERROR';
export const AUTH_LOGOUT: AuthActionType = 'AUTH_LOGOUT';
export const AUTH_GET_PERMISSIONS: AuthActionType = 'AUTH_GET_PERMISSIONS';
export const AUTH_LOGIN = 'AUTH_LOGIN';
export const AUTH_CHECK = 'AUTH_CHECK';
export const AUTH_ERROR = 'AUTH_ERROR';
export const AUTH_LOGOUT = 'AUTH_LOGOUT';
export const AUTH_GET_PERMISSIONS = 'AUTH_GET_PERMISSIONS';

export type AuthActionType =
| typeof AUTH_LOGIN
| typeof AUTH_LOGOUT
| typeof AUTH_ERROR
| typeof AUTH_CHECK
| typeof AUTH_GET_PERMISSIONS;
8 changes: 1 addition & 7 deletions packages/ra-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RouteProps, RouteComponentProps, match as Match } from 'react-router';
import { Location } from 'history';

import { WithPermissionsChildrenParams } from './auth/WithPermissions';
import { AuthActionType } from './auth/types';

export type Identifier = string | number;
export interface Record {
Expand Down Expand Up @@ -36,13 +37,6 @@ export type I18nProvider = {
[key: string]: any;
};

export type AuthActionType =
| 'AUTH_LOGIN'
| 'AUTH_LOGOUT'
| 'AUTH_ERROR'
| 'AUTH_CHECK'
| 'AUTH_GET_PERMISSIONS';

export type AuthProvider = {
login: (params: any) => Promise<any>;
logout: (params: any) => Promise<void | string>;
Expand Down

0 comments on commit bd78647

Please sign in to comment.