Skip to content

Commit f648941

Browse files
committed
its accessToken not authToken
1 parent 7112c9d commit f648941

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/hooks/useAuth.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ export const useAuth = () => {
1313

1414
useEffect(() => {
1515
// Check for auth token and get user info
16-
const token = localStorage.getItem('authToken')
16+
// Support both 'authToken' (legacy) and 'accessToken' (current)
17+
const token = localStorage.getItem('accessToken') || localStorage.getItem('authToken')
1718

1819
if (token) {
1920
// Decode JWT or fetch user info
2021
try {
2122
// Simple JWT decode (in production, verify signature)
2223
const payload = JSON.parse(atob(token.split('.')[1]))
24+
25+
// Get DID from token or localStorage (wallet auth stores it separately)
26+
const did = payload.did || localStorage.getItem('did')
27+
const ethAddress = localStorage.getItem('ethAddress')
28+
2329
setCurrentUser({
2430
id: payload.userId || payload.id,
2531
email: payload.email,
2632
googleId: payload.googleId,
27-
metamaskAddress: payload.metamaskAddress
33+
// Use DID/ethAddress from token or localStorage for wallet auth
34+
metamaskAddress: ethAddress || (did ? did.replace('did:ethr:', '') : undefined)
2835
})
2936
} catch (error) {
3037
console.error('Failed to decode token:', error)

0 commit comments

Comments
 (0)