forked from Satyam1923/Spring-Music-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Satyam1923#196 from Sid-80/auth-redux
feat: auth-redux
- Loading branch information
Showing
6 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.jsx' | ||
import './index.css' | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App.jsx"; | ||
import "./index.css"; | ||
import { Provider } from "react-redux"; | ||
import { store } from "./redux/store.js"; | ||
import { PersistGate } from "redux-persist/integration/react"; | ||
import { persistStore } from "redux-persist"; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) | ||
const persistor = persistStore(store); | ||
|
||
ReactDOM.createRoot(document.getElementById("root")).render( | ||
<PersistGate persistor={persistor}> | ||
<Provider store={store}> | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
</Provider> | ||
</PersistGate> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
const initialState = { | ||
value:{ | ||
username:"", | ||
isAuth:false, | ||
email:"", | ||
} | ||
} | ||
|
||
export const auth = createSlice({ | ||
name:"auth", | ||
initialState, | ||
reducers:{ | ||
logOut:()=>{ | ||
return initialState | ||
}, | ||
logIn:(state,action)=>{ | ||
return { | ||
value : { | ||
isAuth:true, | ||
email:action.payload.email | ||
} | ||
} | ||
}, | ||
setUsername:(state,action) => { | ||
return { | ||
value : { | ||
isAuth:true, | ||
username:action.payload.username | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
export const {logIn,logOut,setUsername} = auth.actions; | ||
export default auth.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
import authReducer from "./auth-slice"; | ||
import storage from 'redux-persist/lib/storage'; | ||
import {persistReducer} from "redux-persist" | ||
import { combineReducers } from "@reduxjs/toolkit"; | ||
|
||
const persistConfig = { | ||
key: 'root', | ||
storage | ||
} | ||
|
||
const reducer = combineReducers({ | ||
auth:authReducer, | ||
}) | ||
|
||
const persistedReducer = persistReducer(persistConfig,reducer) | ||
|
||
export const store=configureStore({ | ||
reducer: persistedReducer, | ||
}) |