@tidecloak/create-nextjs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/create.cjs +139 -0
- package/dist/cjs/create.js.map +1 -0
- package/dist/esm/create.js +134 -0
- package/dist/esm/create.js.map +1 -0
- package/dist/types/create.d.ts +3 -0
- package/dist/types/create.d.ts.map +1 -0
- package/init/.env.example +8 -0
- package/init/realm.json +162 -0
- package/init/tcinit.sh +261 -0
- package/package.json +40 -0
- package/template-js-app/.env.example +0 -0
- package/template-js-app/app/api/protected/route.js +40 -0
- package/template-js-app/app/auth/redirect/page.jsx +46 -0
- package/template-js-app/app/home/page.jsx +101 -0
- package/template-js-app/app/layout.jsx +18 -0
- package/template-js-app/app/page.jsx +64 -0
- package/template-js-app/app/provider.jsx +11 -0
- package/template-js-app/init/.env.example +8 -0
- package/template-js-app/init/realm.json +162 -0
- package/template-js-app/init/tcinit.sh +261 -0
- package/template-js-app/jsconfig.json +9 -0
- package/template-js-app/middleware.js +31 -0
- package/template-js-app/next.config.js +5 -0
- package/template-js-app/package.json +17 -0
- package/template-js-app/public/silent-check-sso.html +1 -0
- package/template-js-app/tidecloak.json +1 -0
- package/template-ts-app/.env.example +0 -0
- package/template-ts-app/app/api/protected/route.ts +38 -0
- package/template-ts-app/app/auth/redirect/page.tsx +46 -0
- package/template-ts-app/app/home/page.tsx +101 -0
- package/template-ts-app/app/layout.tsx +24 -0
- package/template-ts-app/app/page.tsx +65 -0
- package/template-ts-app/app/provider.tsx +23 -0
- package/template-ts-app/init/.env.example +8 -0
- package/template-ts-app/init/realm.json +162 -0
- package/template-ts-app/init/tcinit.sh +261 -0
- package/template-ts-app/middleware.ts +44 -0
- package/template-ts-app/next.config.js +0 -0
- package/template-ts-app/package.json +22 -0
- package/template-ts-app/public/silent-check-sso.html +1 -0
- package/template-ts-app/tidecloak.json +1 -0
- package/template-ts-app/tsconfig.json +42 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// an example nextJS middleware router that does server-side validation on all traffic to secure pages
|
|
2
|
+
import type { NextRequest } from "next/server";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import {
|
|
5
|
+
createTideCloakMiddleware,
|
|
6
|
+
type TideCloakContext,
|
|
7
|
+
} from "@tidecloak/nextjs/server";
|
|
8
|
+
import tcConfig from "./tidecloak.json";
|
|
9
|
+
|
|
10
|
+
export default createTideCloakMiddleware({
|
|
11
|
+
config: tcConfig,
|
|
12
|
+
protectedRoutes: {
|
|
13
|
+
// list each protected route and the roles allowed to access it
|
|
14
|
+
"/protected": ["offline_access"],
|
|
15
|
+
},
|
|
16
|
+
onFailure: (ctx: TideCloakContext, req: NextRequest) => {
|
|
17
|
+
console.debug("Token verification failed", {
|
|
18
|
+
path: req.nextUrl.pathname,
|
|
19
|
+
ctx,
|
|
20
|
+
});
|
|
21
|
+
return NextResponse.json(
|
|
22
|
+
{ error: "Access forbidden: invalid token" },
|
|
23
|
+
{ status: 403 }
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
onSuccess: (ctx: TideCloakContext, req: NextRequest) => {
|
|
27
|
+
return NextResponse.next();
|
|
28
|
+
},
|
|
29
|
+
onError: (
|
|
30
|
+
ctx: TideCloakContext,
|
|
31
|
+
req: NextRequest,
|
|
32
|
+
err: unknown
|
|
33
|
+
) => {
|
|
34
|
+
console.error("[Middleware] error verifying token for", req.nextUrl.pathname, err);
|
|
35
|
+
// if something unexpected happens, redirect to your auth flow
|
|
36
|
+
const redirectUrl = new URL("/auth/redirect", req.url);
|
|
37
|
+
return NextResponse.redirect(redirectUrl);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Tell Next.js which paths to apply this middleware to
|
|
42
|
+
export const config = {
|
|
43
|
+
matcher: ["/protected/:path*"],
|
|
44
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start",
|
|
9
|
+
"init": "bash init/tcinit.sh"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"next": "14.x",
|
|
13
|
+
"react": "18.x",
|
|
14
|
+
"react-dom": "18.x",
|
|
15
|
+
"@tidecloak/nextjs": "^0.9.11"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "24.0.13",
|
|
19
|
+
"@types/react": "19.1.8",
|
|
20
|
+
"typescript": "5.8.3"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<html><body><script>parent.postMessage(location.href, location.origin)</script></body></html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": false,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"module": "esnext",
|
|
16
|
+
"moduleResolution": "node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"jsx": "preserve",
|
|
20
|
+
"baseUrl": ".",
|
|
21
|
+
"paths": {
|
|
22
|
+
"@/*": [
|
|
23
|
+
"*"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"esModuleInterop": true,
|
|
27
|
+
"plugins": [
|
|
28
|
+
{
|
|
29
|
+
"name": "next"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"include": [
|
|
34
|
+
"next-env.d.ts",
|
|
35
|
+
"**/*.ts",
|
|
36
|
+
"**/*.tsx",
|
|
37
|
+
".next/types/**/*.ts"
|
|
38
|
+
],
|
|
39
|
+
"exclude": [
|
|
40
|
+
"node_modules"
|
|
41
|
+
]
|
|
42
|
+
}
|