Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an helper to decode the JWT #69

Merged
merged 3 commits into from
Mar 22, 2024
Merged

Add an helper to decode the JWT #69

merged 3 commits into from
Mar 22, 2024

Conversation

marcomontalbano
Copy link
Member

@marcomontalbano marcomontalbano commented Mar 21, 2024

What I did

I added an helper to decode the JWT.

import { authenticate, jwtDecode, jwtIsSalesChannel } from '@commercelayer/js-auth'

const auth = await authenticate('client_credentials', {
  clientId: '{{ application_client_id }}',
  scope: '{{ application_scope }}'
})

const decodedJWT = jwtDecode(auth.accessToken)

if (jwtIsSalesChannel(decodedJWT.payload)) {
  console.log('organization slug is', decodedJWT.payload.organization.slug)
}

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests).
  • Make sure to add/update documentation regarding your changes.
  • You are NOT deprecating/removing a feature.

@marcomontalbano marcomontalbano added the enhancement New feature or request label Mar 21, 2024
@marcomontalbano marcomontalbano self-assigned this Mar 21, 2024
@marcomontalbano marcomontalbano marked this pull request as ready for review March 21, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants