Skip to content

Commit

Permalink
chore: use js-auth into api
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Jul 12, 2024
1 parent 1c21fe3 commit 8da4800
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/nextjs/src/app/api/test/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { authenticate, jwtVerify } from "@commercelayer/js-auth"
import { NextResponse, type NextRequest } from "next/server"

export async function GET(_request: NextRequest) {
const auth = await authenticate('client_credentials', {
clientId: 'BISG8bb3GWpC8_D7Nt1SuWWdieS5bJq831A50LgB_Ig',
scope: 'market:id:KoaJYhMVVj'
})

const decodedJWT = await jwtVerify(auth.accessToken)

let slug: string

if (!('organization' in decodedJWT.payload)) {
throw new Error('A "sales_channel" token is required.')
}

return NextResponse.json({
from: 'api',
orgSlug: decodedJWT.payload.organization.slug
})
}

0 comments on commit 8da4800

Please sign in to comment.