Skip to content

Commit

Permalink
docs: add proxy example (#9077)
Browse files Browse the repository at this point in the history
* chore: add Preview Deployment example

* simplify package.json

* chore(examples): bump to `next-auth@beta`
  • Loading branch information
balazsorban44 authored Nov 7, 2023
1 parent 4f31135 commit 0ba1d41
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/proxy/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
VERCEL="1"
# https://vercel.com/changelog/corepack-experimental-is-now-available
ENABLE_EXPERIMENTAL_COREPACK="1"

# https://authjs.dev/getting-started/deployment#securing-a-preview-deployment
AUTH_SECRET= # openssl rand -base64 64
AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
15 changes: 15 additions & 0 deletions apps/proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# dependencies
/node_modules

# misc
.DS_Store
*.pem

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
1 change: 1 addition & 0 deletions apps/proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
27 changes: 27 additions & 0 deletions apps/proxy/api/[auth].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Auth, AuthConfig } from "@auth/core"
import GitHub from "@auth/core/providers/github"

export default function handler(req: Request) {
return Auth(req, getDefaults({ providers: [GitHub] }))
}

export const config = { runtime: "edge" }

export function getDefaults(config: AuthConfig) {
config.secret ??= process.env.AUTH_SECRET
config.trustHost ??= !!process.env.VERCEL
config.redirectProxyUrl ??= process.env.AUTH_REDIRECT_PROXY_URL
config.providers = config.providers.map((p) => {
const finalProvider = typeof p === "function" ? p() : p
if (finalProvider.type === "oauth" || finalProvider.type === "oidc") {
const ID = finalProvider.id.toUpperCase()
finalProvider.clientId ??= process.env[`AUTH_${ID}_ID`]
finalProvider.clientSecret ??= process.env[`AUTH_${ID}_SECRET`]
if (finalProvider.type === "oidc") {
finalProvider.issuer ??= process.env[`AUTH_${ID}_ISSUER`]
}
}
return finalProvider
})
return config
}
2 changes: 2 additions & 0 deletions apps/proxy/api/callback/[auth].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from "../[auth].js"
export const config = { runtime: "edge" }
9 changes: 9 additions & 0 deletions apps/proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "proxy",
"description": "Proxy for Auth.js hosted examples",
"private": true,
"type": "module",
"dependencies": {
"@auth/core": "latest"
}
}
21 changes: 21 additions & 0 deletions apps/proxy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ES2020",
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"skipLibCheck": true
},
"include": [
"**/*.ts",
],
"exclude": [
"node_modules",
]
}

1 comment on commit 0ba1d41

@vercel
Copy link

@vercel vercel bot commented on 0ba1d41 Nov 7, 2023

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.