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:
parent
f5ed85427e
commit
e4690d5d9c
11 changed files with 199 additions and 31 deletions
34
client/src/store/reducers/auth.ts
Normal file
34
client/src/store/reducers/auth.ts
Normal 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;
|
||||
}
|
||||
};
|
|
@ -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>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue