2019-12-13 12:56:29 +05:30
|
|
|
import React from 'react';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
|
|
|
|
import { State as AuthState } from './reducer';
|
|
|
|
|
|
|
|
export interface AuthContext {
|
2020-05-24 04:38:24 +05:30
|
|
|
auth: AuthState;
|
|
|
|
user: User;
|
|
|
|
requestRedraw: () => Promise<void>;
|
|
|
|
clearErrors: () => void;
|
2020-10-23 03:53:59 +05:30
|
|
|
resolve: (payload: Record<string, any> | undefined) => Promise<any> | void;
|
|
|
|
reject: (payload: Record<string, any> | undefined) => Promise<any> | void;
|
2019-12-13 12:56:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const Context = React.createContext<AuthContext>({
|
2020-05-24 04:38:24 +05:30
|
|
|
auth: {
|
|
|
|
error: null,
|
|
|
|
login: '',
|
|
|
|
scopes: [],
|
|
|
|
} as any,
|
|
|
|
user: {
|
|
|
|
id: null,
|
|
|
|
isGuest: true,
|
|
|
|
} as any,
|
|
|
|
async requestRedraw() {},
|
|
|
|
clearErrors() {},
|
|
|
|
resolve() {},
|
|
|
|
reject() {},
|
2019-12-13 12:56:29 +05:30
|
|
|
});
|
|
|
|
Context.displayName = 'AuthContext';
|
|
|
|
|
|
|
|
export const { Provider, Consumer } = Context;
|
|
|
|
|
|
|
|
export default Context;
|