From 0d3f7a8622b60f01a164e3b869a3adad44c964e8 Mon Sep 17 00:00:00 2001 From: David Gomes Date: Sat, 10 Aug 2024 22:46:39 +0200 Subject: [PATCH] print jwt token --- .env.template | 4 ++-- app/components/user-details.tsx | 12 ++++++++++++ app/get-token/route.ts | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/get-token/route.ts diff --git a/.env.template b/.env.template index fe97b9f..c676332 100644 --- a/.env.template +++ b/.env.template @@ -1,5 +1,5 @@ -NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_pub_key -CLERK_SECRET_KEY=your_clerk_secret_key +NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY= +CLERK_SECRET_KEY= NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up # NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard diff --git a/app/components/user-details.tsx b/app/components/user-details.tsx index af50edb..9a2f1d1 100644 --- a/app/components/user-details.tsx +++ b/app/components/user-details.tsx @@ -1,6 +1,7 @@ "use client"; import { useOrganization, useSession, useUser } from "@clerk/nextjs"; +import { useEffect } from "react"; function Row({ desc, @@ -61,6 +62,17 @@ export function UserDetails() { const { session } = useSession(); const { organization } = useOrganization(); + useEffect(() => { + fetch("http://localhost:3001/get-token") + .then((res) => res.json()) + .then((data) => { + console.log(data); + }) + .catch((error) => { + console.error("Error:", error); + }); + }, []); + if (!user || !session) return null; return ( diff --git a/app/get-token/route.ts b/app/get-token/route.ts new file mode 100644 index 0000000..d96a3f4 --- /dev/null +++ b/app/get-token/route.ts @@ -0,0 +1,22 @@ +import { auth, clerkClient } from "@clerk/nextjs/server"; + +export async function GET() { + const { sessionId } = auth(); + + if (!sessionId) { + return Response.json({ message: "Unauthorized" }, { status: 401 }); + } + + const template = "Neon"; + + const token = await clerkClient.sessions.getToken(sessionId, template); + + console.log(token); + /* + _Token { + jwt: 'eyJhbG...' + } + */ + + return Response.json({ token }); +}