Skip to content

Commit

Permalink
upgrade and test on staging
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Oct 26, 2024
1 parent e4436e9 commit e14bb5a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/api/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const dynamic = 'force-dynamic'
export async function GET(req: NextRequest): Promise<NextResponse> {
// 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
Expand Down
12 changes: 9 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion fern/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fern/fern.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"organization": "abvthecity",
"version": "0.45.0-rc23"
"version": "0.45.0-rc25"
}

1 comment on commit e14bb5a

@vercel
Copy link

@vercel vercel bot commented on e14bb5a Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.