Skip to content

Commit

Permalink
Merge pull request #25 from PBillingsby/oauth-redirect-result
Browse files Browse the repository at this point in the history
add redirect result to localStorage
  • Loading branch information
joshuascan committed Apr 24, 2024
2 parents 5d4d39d + 11d8d7f commit 3f2bfb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const connector = new DedicatedWalletConnector({
})
```

To retrieve the Magic redirect result when a user is authenticated and logged in, use `JSON.parse(localStorage.getItem("magicRedirectResult"))`. This will give you access to the redirect result object. The object will be removed from localStorage once the user disconnects.


## 📲 Enable SMS Authentication

Expand Down
9 changes: 7 additions & 2 deletions src/lib/connectors/dedicatedWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export function dedicatedWalletConnector({
try {
const magic = getMagicSDK()
await magic?.wallet.disconnect()
localStorage.removeItem('magicRedirectResult')
config.emitter.emit('disconnect')
} catch (error) {
console.error('Error disconnecting from Magic SDK:', error)
Expand Down Expand Up @@ -221,11 +222,15 @@ export function dedicatedWalletConnector({
}

const isLoggedIn = await magic.user.isLoggedIn()
const result = await magic.oauth.getRedirectResult()
if (result) {
localStorage.setItem('magicRedirectResult', JSON.stringify(result))
}

if (isLoggedIn) return true

const result = await magic.oauth.getRedirectResult()
return result !== null
} catch {}
} catch { }
return false
},

Expand Down

0 comments on commit 3f2bfb1

Please sign in to comment.