generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add authSlice - set auth vars on login/logout
- Loading branch information
1 parent
8e6ce2d
commit 9c6fefd
Showing
6 changed files
with
69 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"; | ||
import { IProvider } from "@web3auth/base"; | ||
|
||
export type AuthProvider = IProvider | null; | ||
|
||
export interface AuthRootState { | ||
auth: { | ||
isConnected: boolean; | ||
provider: AuthProvider; | ||
}; | ||
} | ||
|
||
interface AuthState { | ||
isConnected: boolean; | ||
provider: AuthProvider; | ||
} | ||
|
||
export const authSlice = createSlice({ | ||
name: "auth", | ||
initialState: { | ||
isConnected: false, | ||
provider: null as AuthProvider, | ||
}, | ||
reducers: { | ||
setAuthProvider: (state: AuthState, action: PayloadAction<{ provider: AuthProvider }>) => { | ||
state.provider = action.payload.provider; | ||
}, | ||
|
||
setIsConnected: (state: AuthState, action: PayloadAction<{ isConnected: boolean }>) => { | ||
state.isConnected = action.payload.isConnected; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setAuthProvider, setIsConnected } = authSlice.actions; | ||
|
||
export default authSlice.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
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
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