1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-06 19:25:17 +02:00

Added auth form. Added login and logout actions

This commit is contained in:
Paweł Malak 2021-11-10 13:53:28 +01:00
parent f5ed85427e
commit e4690d5d9c
11 changed files with 199 additions and 31 deletions

View file

@ -0,0 +1,34 @@
import { Action } from '../actions';
import { ActionType } from '../action-types';
interface AuthState {
isAuthenticated: boolean;
token: string | null;
}
const initialState: AuthState = {
isAuthenticated: false,
token: null,
};
export const authReducer = (
state: AuthState = initialState,
action: Action
): AuthState => {
switch (action.type) {
case ActionType.login:
return {
...state,
token: action.payload,
isAuthenticated: true,
};
case ActionType.logout:
return {
...state,
token: null,
isAuthenticated: false,
};
default:
return state;
}
};

View file

@ -5,6 +5,7 @@ import { configReducer } from './config';
import { notificationReducer } from './notification';
import { appsReducer } from './app';
import { bookmarksReducer } from './bookmark';
import { authReducer } from './auth';
export const reducers = combineReducers({
theme: themeReducer,
@ -12,6 +13,7 @@ export const reducers = combineReducers({
notification: notificationReducer,
apps: appsReducer,
bookmarks: bookmarksReducer,
auth: authReducer,
});
export type State = ReturnType<typeof reducers>;