-
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 #40 from EveripediaNetwork/fix-return-user-form-us…
…eauth-hook-0052 return user form useAuth hook
- Loading branch information
Showing
5 changed files
with
137 additions
and
51 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,5 @@ | ||
--- | ||
"@everipedia/iq-login": patch | ||
--- | ||
|
||
Returns the user from web3auth hook |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { UserInfo } from "@web3auth/base"; | ||
import type { Web3Auth } from "@web3auth/modal"; | ||
import { createContext, useContext, useEffect, useState } from "react"; | ||
|
||
const Web3AuthContext = createContext<{ | ||
web3Auth: Web3Auth | null; | ||
user: Partial<UserInfo> | null; | ||
}>({ web3Auth: null, user: null }); | ||
|
||
export function Web3AuthProvider({ | ||
children, | ||
web3AuthInstance, | ||
}: { children: React.ReactNode; web3AuthInstance: Web3Auth }) { | ||
const [user, setUser] = useState<Partial<UserInfo> | null>(null); | ||
|
||
useEffect(() => { | ||
const checkLoggedInUser = async () => { | ||
if (web3AuthInstance.connected) { | ||
const user = await web3AuthInstance.getUserInfo(); | ||
setUser(user); | ||
} | ||
}; | ||
|
||
checkLoggedInUser(); | ||
}, [web3AuthInstance]); | ||
|
||
return ( | ||
<Web3AuthContext.Provider value={{ web3Auth: web3AuthInstance, user }}> | ||
{children} | ||
</Web3AuthContext.Provider> | ||
); | ||
} | ||
|
||
export function useWeb3Auth() { | ||
return useContext(Web3AuthContext); | ||
} |
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