-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move `fetchPanoptesUser` into a helper. - add explanatory comments. - restore the missing `avatar_src` when getting the user object from a JWT.
- Loading branch information
1 parent
c0a8128
commit 3367e6e
Showing
3 changed files
with
48 additions
and
31 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,34 @@ | ||
import auth from 'panoptes-client/lib/auth' | ||
import { auth as authHelpers } from '@zooniverse/panoptes-js' | ||
|
||
export default async function fetchPanoptesUser(storedUser) { | ||
try { | ||
const jwt = await auth.checkBearerToken() | ||
/* | ||
`crypto.subtle` is needed to decrypt the Panoptes JWT. | ||
It will only exist for https:// URLs. | ||
*/ | ||
const isSecure = crypto?.subtle | ||
if (jwt && isSecure) { | ||
/* | ||
avatar_src isn't encoded in the Panoptes JWT, so we need to add it. | ||
https://github.com/zooniverse/panoptes/issues/4217 | ||
*/ | ||
const { user, error } = await authHelpers.decodeJWT(jwt) | ||
if (user) { | ||
const { admin, display_name, id, login } = user | ||
return { | ||
avatar_src: storedUser.avatar_src, | ||
...user | ||
} | ||
} | ||
if (error) { | ||
throw error | ||
} | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
const { admin, avatar_src, display_name, id, login } = await auth.checkCurrent() | ||
return { admin, avatar_src, display_name, id, login } | ||
} |
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 @@ | ||
export { default as fetchPanoptesUser } from './fetchPanoptesUser.js' |
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