mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
removed old authentication slice
Signed-off-by: Andrii Podriez <andrey5577990@gmail.com>
This commit is contained in:
parent
3e441fd3bd
commit
399c993fc8
2 changed files with 0 additions and 99 deletions
|
@ -16,7 +16,6 @@
|
|||
******************************************************************************/
|
||||
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import userReducer from './userSlice';
|
||||
import icReducer from './icSlice';
|
||||
import configReducer from './configSlice'
|
||||
import { apiSlice } from "./apiSlice";
|
||||
|
@ -25,7 +24,6 @@ import authReducer from './authSlice';
|
|||
export const store = configureStore({
|
||||
reducer: {
|
||||
auth: authReducer,
|
||||
user: userReducer,
|
||||
infrastructure: icReducer,
|
||||
config: configReducer,
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/**
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* VILLASweb is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
import {createSlice, createAsyncThunk} from '@reduxjs/toolkit'
|
||||
import RestAPI from '../common/api/rest-api';
|
||||
|
||||
const userSlice = createSlice({
|
||||
name: 'user',
|
||||
initialState: {
|
||||
currentUser: null,
|
||||
currentToken: null,
|
||||
isLoading: false,
|
||||
loginMessage: ''},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(login.pending, (state, action) => {
|
||||
state.isLoading = true
|
||||
})
|
||||
.addCase(login.fulfilled, (state, action) => {
|
||||
state.isLoading = false
|
||||
state.currentUser = action.payload.user
|
||||
state.currentToken = action.payload.token
|
||||
|
||||
localStorage.setItem('currentUser', JSON.stringify(action.payload.user));
|
||||
localStorage.setItem('token', action.payload.token);
|
||||
})
|
||||
.addCase(login.rejected, (state, action) => {
|
||||
state.loginMessage = 'Wrong credentials! Please try again.'
|
||||
})
|
||||
.addCase(logout.pending, (state) => {
|
||||
state.currentUser = null
|
||||
state.currentToken = null
|
||||
})
|
||||
.addCase(loginExternal.pending, (state, action) => {
|
||||
state.isLoading = true
|
||||
})
|
||||
.addCase(loginExternal.fulfilled, (state, action) => {
|
||||
state.isLoading = false
|
||||
state.currentUser = action.payload.user
|
||||
state.currentToken = action.payload.token
|
||||
|
||||
localStorage.setItem('currentUser', JSON.stringify(action.payload.user));
|
||||
localStorage.setItem('token', action.payload.token);
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const login = createAsyncThunk(
|
||||
'user/login',
|
||||
async (userData, thunkAPI) => {
|
||||
try {
|
||||
const res = await RestAPI.post('/api/v2/authenticate/internal', userData)
|
||||
return {user: res.user, token: res.token}
|
||||
} catch(error) {
|
||||
console.log('Error while trying to log in: ', error)
|
||||
return thunkAPI.rejectWithValue(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const loginExternal = createAsyncThunk(
|
||||
'user/loginExternal',
|
||||
async (data, thunkAPI) => {
|
||||
try {
|
||||
const res = await RestAPI.post(this.makeURL('/authenticate/external'), null, null, 60000)
|
||||
|
||||
return {user: res.user, token: res.token}
|
||||
} catch(error) {
|
||||
console.log('Error while trying to log in externally: ', error)
|
||||
return thunkAPI.rejectWithValue(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const logout = createAsyncThunk(
|
||||
'user/logout',
|
||||
async () => {
|
||||
//remove token and current user from local storage
|
||||
localStorage.clear();
|
||||
}
|
||||
)
|
||||
|
||||
export default userSlice.reducer
|
Loading…
Add table
Reference in a new issue