Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored and jonas-jonas committed Oct 30, 2024
1 parent bdc4c7b commit cd18d78
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 5 deletions.
25 changes: 25 additions & 0 deletions packages/nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions packages/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# nextjs

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build nextjs` to build the library.

## Running unit tests

Run `nx test nextjs` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions packages/nextjs/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: "nextjs",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/packages/nextjs",
}
38 changes: 38 additions & 0 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@ory/nextjs",
"version": "0.0.1",
"type": "commonjs",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts",
"private": false,
"dependencies": {
"@ory/client-fetch": "^1.15.6",
"@types/set-cookie-parser": "^2.4.10",
"cookie": "^1.0.1",
"set-cookie-parser": "^2.7.0",
"tldjs": "^2.3.1",
"tslib": "^2.3.0"
},
"devDependencies": {
"@types/cookie": "^0.6.0",
"@types/tldjs": "^2.3.4",
"next": "^14.2.15"
},
"keywords": [
"ory",
"auth",
"react",
"passwordless",
"login",
"user management",
"permissions",
"authentication",
"nextjs",
"vercel",
"app router",
"pages router"
],
"peerDependencies": {
"next": ">=13.1.0"
}
}
19 changes: 19 additions & 0 deletions packages/nextjs/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "nextjs",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/nextjs/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "packages/nextjs/dist",
"main": "packages/nextjs/src/index.ts",
"tsConfig": "packages/nextjs/tsconfig.lib.json",
"assets": ["packages/nextjs/*.md"]
}
}
}
}
22 changes: 17 additions & 5 deletions packages/nextjs/src/server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { filterRequestHeaders, processSetCookieHeaders } from "../utils"
import { OryConfig } from "../types"
import { defaultOmitHeaders } from "../headers"

function getProjectSdkUrl(options: OryConfig) {
function getProjectSdkUrl() {
let baseUrl = ""

if (process.env["ORY_SDK_URL"]) {
Expand All @@ -14,13 +14,23 @@ function getProjectSdkUrl(options: OryConfig) {
return baseUrl.replace(/\/$/, "")
}

function getProjectApiKey() {
let baseUrl = ""

if (process.env["ORY_PROJECT_API_TOKEN"]) {
baseUrl = process.env["ORY_PROJECT_API_TOKEN"]
}

return baseUrl.replace(/\/$/, "")
}

async function proxyRequest(request: NextRequest, options: OryConfig) {
const match = ["/self-service", "/sessions/whoami", "/ui"]
if (!match.some((m) => request.nextUrl.pathname.startsWith(m))) {
return NextResponse.next()
}

const matchBaseUrl = new URL(getProjectSdkUrl(options))
const matchBaseUrl = new URL(getProjectSdkUrl())
const selfUrl = request.nextUrl.protocol + "//" + request.nextUrl.host

const upstreamUrl = request.nextUrl.clone()
Expand All @@ -35,9 +45,11 @@ async function proxyRequest(request: NextRequest, options: OryConfig) {
)
requestHeaders.set("Host", upstreamUrl.hostname)

// Special headers for Ory Network URL rewrites (disabled for now):
requestHeaders.set("X-Ory-Base-URL-Rewrite", "false")
requestHeaders.set("Ory-Base-URL-Rewrite", "false")
// Ensures we use the correct URL in redirects like OIDC redirects.
requestHeaders.set("Ory-Base-URL-Rewrite", selfUrl.toString())
requestHeaders.set("Ory-Base-URL-Rewrite-Token", getProjectApiKey())

// We disable custom domain redirects.
requestHeaders.set("Ory-No-Custom-Domain-Redirect", "true")

// Fetch the upstream response
Expand Down
23 changes: 23 additions & 0 deletions packages/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"rootDir": "./src"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/nextjs/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"rootDir": "./src"
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
15 changes: 15 additions & 0 deletions packages/nextjs/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"],
"rootDir": "./src"
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

0 comments on commit cd18d78

Please sign in to comment.