Skip to content

Commit

Permalink
print jwt token
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgomes committed Aug 10, 2024
1 parent 772b4a5 commit 0d3f7a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions app/components/user-details.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { useOrganization, useSession, useUser } from "@clerk/nextjs";
import { useEffect } from "react";

function Row({
desc,
Expand Down Expand Up @@ -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 (
Expand Down
22 changes: 22 additions & 0 deletions app/get-token/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}

0 comments on commit 0d3f7a8

Please sign in to comment.