From e14bb5a0c8cb315c6e9eae9acdca5661a2b6550a Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Fri, 25 Oct 2024 23:17:24 -0400 Subject: [PATCH] upgrade and test on staging --- app/api/login/route.ts | 2 +- app/page.tsx | 12 +++++++++--- auth/utils.ts | 2 +- fern/docs.yml | 3 ++- fern/fern.config.json | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/api/login/route.ts b/app/api/login/route.ts index 9036117..fb93bf6 100644 --- a/app/api/login/route.ts +++ b/app/api/login/route.ts @@ -12,7 +12,7 @@ export const dynamic = 'force-dynamic' export async function GET(req: NextRequest): Promise { // Step 1. mint the fern_token const fern_token = await signFernJWT({ - // roles?: [] <-- set audience filters here + // roles?: [] <-- set viewer roles here }) // Step 2. preserve the state diff --git a/app/page.tsx b/app/page.tsx index c4288c5..bcdc887 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -15,14 +15,20 @@ export default function Home(props: HomeProps) { // please see `app/api/login/route.ts` for a full implementation. async function handleSubmit(formData: FormData) { 'use server' + + // 1. validate input const roles = formData .getAll('role') .filter((role): role is string => allRoles.includes(String(role))) - const fern_token = await signFernJWT({ - roles: roles.length > 0 ? roles : undefined, - }) + + // 2.mint token + const fern_token = await signFernJWT({ roles }) + + // 3. preserve state const state = typeof searchParams['state'] === 'string' ? searchParams['state'] : null + + // 4. redirect to fern docs const url = createCallbackUrl(fern_token, state) redirect(url.toString()) } diff --git a/auth/utils.ts b/auth/utils.ts index 606443e..757e398 100644 --- a/auth/utils.ts +++ b/auth/utils.ts @@ -4,7 +4,7 @@ import { SignJWT } from 'jose' const JWT_ISSUER = 'https://test-jwt-auth-smoky.vercel.app' // this is the domain of your docs, (or, if subpathed, use the apex here: yourdomain.com); -const DOCS_ORIGIN = 'https://test-jwt-auth-smoky.docs.buildwithfern.com' +const DOCS_ORIGIN = 'https://test-jwt-auth-smoky.docs.staging.buildwithfern.com' // this is path that you will redirect to in the docs instance, and let Fern set the fern_token. This is preferred. // alternatively, you may opt to set the `Set-Cookie` header directly using `fern_token` (case sensitive) if on the same domain. diff --git a/fern/docs.yml b/fern/docs.yml index 9b5706d..bff44dc 100644 --- a/fern/docs.yml +++ b/fern/docs.yml @@ -23,10 +23,11 @@ navigation: - api: API Reference (Public) layout: - endpoint: POST /create-movie + title: Create Movie (Customers) viewers: - customers - - api: API Reference (Authed) + - api: API Reference (Customers, Employees) summary: test.mdx viewers: - customers diff --git a/fern/fern.config.json b/fern/fern.config.json index 5380457..69b7c4e 100644 --- a/fern/fern.config.json +++ b/fern/fern.config.json @@ -1,4 +1,4 @@ { "organization": "abvthecity", - "version": "0.45.0-rc23" + "version": "0.45.0-rc25" }