Skip to content

Commit

Permalink
fix(unlock-app): ensuring that users are connected
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 committed Nov 13, 2024
1 parent 55a4697 commit 61cac23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion unlock-app/src/config/PrivyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import AuthenticationContext from '~/contexts/AuthenticationContext'
export const onSignedInWithPrivy = async (user: any) => {
try {
const accessToken = await privyGetAccessToken()
if (!accessToken) {
console.error('No access token found in Privy')
return null
}
const walletAddress = user.wallet.address
if (walletAddress) {
const response = await locksmith.loginWithPrivy({
accessToken: accessToken!,
accessToken,
walletAddress,
})
const { accessToken: locksmithAccessToken } = response.data
Expand All @@ -30,6 +34,7 @@ export const onSignedInWithPrivy = async (user: any) => {
window.dispatchEvent(
new CustomEvent('locksmith.authenticated', { detail: walletAddress })
)
return walletAddress
}
} else {
console.error(
Expand Down
4 changes: 1 addition & 3 deletions unlock-app/src/hooks/useAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ export function useAuthenticate() {
const signInWithPrivy = async ({ onshowUI }: { onshowUI: () => void }) => {
if (!(await signInWithExistingSession())) {
setAccount(undefined)
if (privyAuthenticated) {
await onSignedInWithPrivy(user)
} else {
if (!privyAuthenticated || !(await onSignedInWithPrivy(user))) {
privyLogin()
onshowUI()
}
Expand Down

0 comments on commit 61cac23

Please sign in to comment.