Skillov-fe/src/features/auth/authSlice.js
2025-01-28 12:33:29 +05:30

29 lines
611 B
JavaScript

import { createSlice } from '@reduxjs/toolkit';
const initialState = {
user: null,
isAuthenticated: false,
error: null,
};
const authSlice = createSlice({
name: 'auth',
initialState,
reducers: {
loginSuccess: (state, action) => {
state.user = action.payload;
state.isAuthenticated = true;
},
logout: (state) => {
state.user = null;
state.isAuthenticated = false;
},
setError: (state, action) => {
state.error = action.payload;
},
},
});
export const { loginSuccess, logout, setError } = authSlice.actions;
export default authSlice.reducer;