next-ts-cli 1.0.14 → 1.0.16
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/index.js
CHANGED
|
@@ -87,5 +87,5 @@ CLERK_SECRET_KEY="sk_test_..."
|
|
|
87
87
|
# Vercel AI Gateway
|
|
88
88
|
# https://ai-sdk.dev/docs/getting-started/nextjs-app-router
|
|
89
89
|
AI_GATEWAY_API_KEY="sk_..."
|
|
90
|
-
`),l};import b from"path";import F from"fs-extra";import ue from"path";import ge from"fs-extra";import mt from"sort-package-json";var fe={"better-auth":"^1.
|
|
90
|
+
`),l};import b from"path";import F from"fs-extra";import ue from"path";import ge from"fs-extra";import mt from"sort-package-json";var fe={"better-auth":"^1.5.6","drizzle-kit":"^0.31.10","drizzle-orm":"^0.45.1",postgres:"^3.4.8",tailwindcss:"^4.2.2",postcss:"^8.5.8","@tailwindcss/postcss":"^4.2.2","@biomejs/biome":"2.4.8","@supabase/ssr":"^0.9.0","@supabase/supabase-js":"^2.100.0","@stripe/react-stripe-js":"^5.6.1","@stripe/stripe-js":"^8.11.0",stripe:"^20.4.1","@clerk/nextjs":"^7.0.6","@neondatabase/serverless":"^1.0.2",ai:"^6.0.137","@ai-sdk/react":"^3.0.139"};var d=e=>{let{dependencies:t,devMode:s,projectDir:n}=e,o=ge.readJSONSync(ue.join(n,"package.json"));t.forEach(r=>{let c=fe[r];s&&o.devDependencies?o.devDependencies[r]=c:o.dependencies&&(o.dependencies[r]=c)});let i=mt(o);ge.writeJSONSync(ue.join(n,"package.json"),i,{spaces:2})};var he=({projectDir:e,packages:t})=>{let s=t?.drizzle.inUse;d({projectDir:e,dependencies:["better-auth"],devMode:!1});let o=b.join(p,"template/extras"),i=b.join(o,"better-auth"),r="api/auth/[...all]/route.ts",c=b.join(i,r),l=b.join(e,"app",r);F.copySync(c,l);let m=b.join(i,"auth-client.ts"),h=b.join(e,"lib/auth-client.ts");F.copySync(m,h);let J=b.join(i,s?"with-drizzle-auth.ts":"base-auth.ts"),Le=b.join(e,"lib","auth.ts");F.copySync(J,Le)};import w from"path";import ye from"fs-extra";import ft from"path";import be from"fs-extra";import ut from"sort-package-json";var v=e=>{let{scripts:t,projectDir:s}=e,n=ft.join(s,"package.json"),o=be.readJSONSync(n);o.scripts={...o.scripts,...t};let i=ut(o);be.writeJSONSync(n,i,{spaces:2})};var ke=({projectDir:e})=>{d({projectDir:e,dependencies:["drizzle-kit"],devMode:!0}),d({projectDir:e,dependencies:["drizzle-orm","postgres"],devMode:!1});let t=w.join(p,"template/extras"),s=w.join(t,"drizzle"),n=w.join(s,"drizzle.config.ts"),o=w.join(e,"drizzle.config.ts");ye.copySync(n,o);let i=w.join(s,"db"),r=w.join(e,"lib/db");ye.copySync(i,r),v({projectDir:e,scripts:{"db:push":"drizzle-kit push","db:studio":"drizzle-kit studio","db:generate":"drizzle-kit generate","db:migrate":"drizzle-kit migrate"}})};import y from"path";import H from"fs-extra";var Se=({projectDir:e})=>{let t=y.join(p,"template/extras"),s=y.join(t,"docker");H.copySync(y.join(s,"Dockerfile"),y.join(e,"Dockerfile")),H.copySync(y.join(s,"docker-compose.prod.yml"),y.join(e,"docker-compose.prod.yml")),H.copySync(y.join(s,".dockerignore"),y.join(e,".dockerignore")),v({projectDir:e,scripts:{"docker:build":"docker compose -f docker-compose.prod.yml build","docker:up":"docker compose -f docker-compose.prod.yml up -d","docker:down":"docker compose -f docker-compose.prod.yml down","docker:logs":"docker compose -f docker-compose.prod.yml logs -f","docker:exec":"docker compose -f docker-compose.prod.yml exec app sh","docker:exec:bash":"docker compose -f docker-compose.prod.yml exec app bash","docker:exec:sh":"docker compose -f docker-compose.prod.yml exec app sh","docker:exec:npm":"docker compose -f docker-compose.prod.yml exec app npm"}})};import A from"path";import _e from"fs-extra";import D from"path";import k from"fs-extra";var P=e=>{let{serverName:t,serverConfig:s,projectDir:n}=e;gt({serverName:t,serverConfig:s,projectDir:n}),ht({serverName:t,serverConfig:s,projectDir:n})},gt=e=>{let{serverName:t,serverConfig:s,projectDir:n}=e,o=D.join(n,".cusror/mpc.json");k.ensureDirSync(D.dirname(o));let i={args:s.args,command:s.command,env:s.env,url:s.url},r={};k.existsSync(o)&&(r=k.readJSONSync(o)),r.mcpServers||(r.mcpServers={}),r.mcpServers[t]={...i},k.writeJSONSync(o,r,{spaces:" "})},ht=e=>{let{serverName:t,serverConfig:s,projectDir:n}=e,o=D.join(n,".vscode/mcp.json");k.ensureDirSync(D.dirname(o));let i={};k.existsSync(o)&&(i=k.readJSONSync(o)),i.servers||(i.servers={}),i.servers[t]={...s},k.writeJSONSync(o,i,{spaces:" "})};var xe=({projectDir:e})=>{d({projectDir:e,dependencies:["@supabase/ssr","@supabase/supabase-js"],devMode:!1});let t=A.join(p,"template/extras"),s=A.join(t,"supabase"),n=A.join(s,"supabase"),o=A.join(e,"lib/supabase"),i=A.join(s,"proxy.ts"),r=A.join(e,"proxy.ts");_e.copySync(i,r),_e.copySync(n,o),P({serverName:"supabase",serverConfig:{type:"http",url:"https://mcp.supabase.com/mcp?project_ref=<YOUR_SUPABASE_PROJECT_ID>"},projectDir:e})};import g from"path";import G from"fs-extra";var ve=({projectDir:e})=>{d({projectDir:e,dependencies:["stripe","@stripe/stripe-js","@stripe/react-stripe-js"],devMode:!1});let t=g.join(p,"template/extras"),s=g.join(t,"stripe"),n=g.join(s,"checkout_session"),o=g.join(e,"app/api/checkout_session");G.copySync(n,o);let i=g.join(s,"webhook/stripe/route.ts"),r=g.join(e,"app/api/webhook/stripe/route.ts");G.copySync(i,r);let c=g.join(s,"stripe.ts"),l=g.join(e,"lib/stripe.ts");G.copySync(c,l);let m=g.join(s,"prices.ts"),h=g.join(e,"actions/prices.ts");G.copySync(m,h),v({projectDir:e,scripts:{"webhook:local":"stripe listen --forward-to localhost:3000/api/webhook/stripe"}}),P({serverName:"stripe",serverConfig:{type:"http",url:"https://mcp.stripe.com"},projectDir:e})};import I from"path";import Y from"fs-extra";var we=({projectDir:e})=>{let t=I.join(p,"template/extras"),s=I.join(t,"shadcnui"),n=I.join(s,"components.json"),o=I.join(e,"components.json");Y.copySync(n,o);let i=I.join(s,"globals.css"),r=I.join(e,"app/globals.css");Y.writeFileSync(r,Y.readFileSync(i,"utf8")),P({serverName:"shadcn",serverConfig:{command:"npx",args:["shadcn@latest","mcp"]},projectDir:e})};import E from"path";import Pe from"fs-extra";var Ae=({projectDir:e})=>{d({projectDir:e,dependencies:["@clerk/nextjs"],devMode:!1});let t=E.join(p,"template/extras"),s=E.join(t,"clerk"),n=E.join(s,"proxy.ts"),o=E.join(e,"proxy.ts");Pe.copySync(n,o);let i=E.join(s,"layout.tsx"),r=E.join(e,"app/layout.tsx");Pe.copySync(i,r)};import Ie from"path";import bt from"fs-extra";var Ee=({projectDir:e,packages:t})=>{if(d({projectDir:e,dependencies:["@neondatabase/serverless"],devMode:!1}),t?.drizzle.inUse){let s=Ie.join(p,"template/extras/neon/index.ts"),n=Ie.join(e,"lib/db/index.ts");bt.copySync(s,n)}};import L from"path";import yt from"fs-extra";var Ce=({projectDir:e})=>{d({projectDir:e,dependencies:["ai","@ai-sdk/react"],devMode:!1});let t=L.join(p,"template/extras"),s=L.join(t,"vercel-ai"),n=L.join(s,"route.ts"),o=L.join(e,"app/api/chat/route.ts");yt.copySync(n,o)};var je=e=>({docker:{inUse:e.includes("docker"),installer:Se},betterAuth:{inUse:e.includes("betterAuth"),installer:he},drizzle:{inUse:e.includes("drizzle"),installer:ke},envVariables:{inUse:!0,installer:me},supabase:{inUse:e.includes("supabase"),installer:xe},stripe:{inUse:e.includes("stripe"),installer:ve},shadcnui:{inUse:e.includes("shadcnui"),installer:we},clerk:{inUse:e.includes("clerk"),installer:Ae},neon:{inUse:e.includes("neon"),installer:Ee},vercelAi:{inUse:e.includes("vercelAi"),installer:Ce}});import Te from"path";var ze=e=>{let s=N(e).split("/"),n=s[s.length-1];if(n==="."){let r=Te.resolve(process.cwd());n=Te.basename(r)}let o=s.findIndex(r=>r.startsWith("@"));s.findIndex(r=>r.startsWith("@"))!==-1&&(n=s.slice(o).join("/"));let i=s.filter(r=>!r.startsWith("@")).join("/");return[n,i]};import kt from"gradient-string";var St=["#003f5b","#5f5195","#cc4c91","#ff6f4e","#ff7030","#f10062","#b1008f","#2c19a8"],Re=()=>{let e=kt(St),t=u();(t==="yarn"||t==="pnpm")&&console.log(""),console.log(e.multiline(Q))};import _t from"chalk";import{execa as Ue}from"execa";import Me from"ora";var X=async(e,t,s)=>{let{onDataHandle:n,args:o=["install"],stdout:i="pipe"}=s,r=Me(`Running ${t} install...`).start(),c=Ue(t,o,{cwd:e,stdout:i});return await new Promise((l,m)=>{n&&c.stdout?.on("data",n(r)),c.on("error",h=>m(h)),c.on("close",()=>l())}),r},xt=async(e,t)=>{switch(e){case"npm":return await Ue(e,["install"],{cwd:t,stderr:"inherit"}),null;case"pnpm":return X(t,e,{onDataHandle:s=>n=>{let o=n.toString();o.includes("Progress")&&(s.text=o.includes("|")?o.split(" | ")[1]??"":o)}});case"yarn":return X(t,e,{onDataHandle:s=>n=>{s.text=n.toString()}});case"bun":return X(t,e,{stdout:"ignore"})}},Ne=async({projectDir:e})=>{a.info("Installing dependencies...");let t=u();(await xt(t,e)??Me()).succeed(_t.green(`Successfully installed dependencies!
|
|
91
91
|
`))};import{execSync as vt}from"child_process";import wt from"https";var Oe=e=>{let t=x();t.includes("beta")?(a.warn(" You are using a beta version of next-ts-cli."),a.warn(" Please report any bugs you encounter.")):t.includes("next")?(a.warn(" You are running next-ts-cli with the @next tag which is no longer maintained."),a.warn(" Please run the CLI with @latest instead.")):t!==e&&(a.warn(" You are using an outdated version of next-ts-cli."),a.warn(" Your version:",t+".","Latest version in the npm registry:",e),a.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")};function Pt(){return new Promise((e,t)=>{wt.get("https://registry.npmjs.org/-/package/next-ts-cli/dist-tags",s=>{if(s.statusCode===200){let n="";s.on("data",o=>{n+=o}),s.on("end",()=>{e(JSON.parse(n).latest)})}else t()}).on("error",()=>{t()})})}var Be=()=>Pt().catch(()=>{try{return vt("npm view next-ts-cli version").toString().trim()}catch{return null}});var It=async()=>{let e=await Be(),t=u();Re(),e&&Oe(e);let{appName:s,packages:n,flags:{alias:o}}=await te(),i=je(n),[r,c]=ze(s),l=await re({projectName:c,scopedAppName:r,packages:i,alias:o}),m=Ge.readJSONSync(De.join(l,"package.json"));if(m.name=r,m.nextTsMetadata={initVersion:x()},t!=="bun"){let{stdout:h}=await At(t,["-v"],{cwd:l});m.packageManager=`${t}@${h.trim()}`}Ge.writeJSONSync(De.join(l,"package.json"),m,{spaces:2}),o!=="@/"&&de(l,o),await Ne({projectDir:l}),await le(l),await ce({projectName:c}),process.exit(0)};It().catch(e=>{a.error("Aborting installation..."),e instanceof Error?a.error(e):(a.error("An unknown error has occurred. Please open an issue on github with the below:"),console.log(e)),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-ts-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Create production-ready web application with the Next.js",
|
|
5
5
|
"author": "Daniele Rossino <daniele.rossino10@gmail.com>",
|
|
6
6
|
"maintainers": [],
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=22.0.0"
|
|
35
35
|
},
|
|
36
|
-
"packageManager": "npm@11.
|
|
36
|
+
"packageManager": "npm@11.12.0",
|
|
37
37
|
"scripts": {
|
|
38
38
|
"typecheck": "tsc",
|
|
39
39
|
"build": "tsup",
|
|
@@ -44,54 +44,54 @@
|
|
|
44
44
|
"format": "biome format --write",
|
|
45
45
|
"lint:fix": "biome check --write",
|
|
46
46
|
"release": "changeset version",
|
|
47
|
-
"pub:release": "npm build && npm publish"
|
|
47
|
+
"pub:release": "npm run build && npm publish"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@ai-sdk/react": "^3.0.
|
|
51
|
-
"@clack/core": "^
|
|
52
|
-
"@clack/prompts": "^
|
|
53
|
-
"@clerk/nextjs": "^
|
|
50
|
+
"@ai-sdk/react": "^3.0.139",
|
|
51
|
+
"@clack/core": "^1.1.0",
|
|
52
|
+
"@clack/prompts": "^1.1.0",
|
|
53
|
+
"@clerk/nextjs": "^7.0.6",
|
|
54
54
|
"@neondatabase/serverless": "^1.0.2",
|
|
55
|
-
"@stripe/react-stripe-js": "^5.
|
|
56
|
-
"@stripe/stripe-js": "^8.
|
|
57
|
-
"@supabase/ssr": "^0.
|
|
58
|
-
"@supabase/supabase-js": "^2.
|
|
59
|
-
"ai": "^6.0.
|
|
55
|
+
"@stripe/react-stripe-js": "^5.6.1",
|
|
56
|
+
"@stripe/stripe-js": "^8.11.0",
|
|
57
|
+
"@supabase/ssr": "^0.9.0",
|
|
58
|
+
"@supabase/supabase-js": "^2.100.0",
|
|
59
|
+
"ai": "^6.0.137",
|
|
60
60
|
"chalk": "5.6.2",
|
|
61
|
-
"commander": "^14.0.
|
|
61
|
+
"commander": "^14.0.3",
|
|
62
62
|
"execa": "^9.6.1",
|
|
63
|
-
"fs-extra": "^11.
|
|
63
|
+
"fs-extra": "^11.3.4",
|
|
64
64
|
"gradient-string": "^3.0.0",
|
|
65
|
-
"ora": "9.
|
|
66
|
-
"sort-package-json": "^3.6.
|
|
67
|
-
"stripe": "^20.1
|
|
65
|
+
"ora": "9.3.0",
|
|
66
|
+
"sort-package-json": "^3.6.1",
|
|
67
|
+
"stripe": "^20.4.1"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@auth/drizzle-adapter": "^1.1
|
|
71
|
-
"@biomejs/biome": "2.
|
|
72
|
-
"@changesets/changelog-github": "^0.
|
|
73
|
-
"@changesets/cli": "^2.
|
|
74
|
-
"@libsql/client": "^0.
|
|
70
|
+
"@auth/drizzle-adapter": "^1.11.1",
|
|
71
|
+
"@biomejs/biome": "2.4.8",
|
|
72
|
+
"@changesets/changelog-github": "^0.6.0",
|
|
73
|
+
"@changesets/cli": "^2.30.0",
|
|
74
|
+
"@libsql/client": "^0.17.2",
|
|
75
75
|
"@planetscale/database": "^1.19.0",
|
|
76
|
-
"@tailwindcss/postcss": "^4.
|
|
77
|
-
"@total-typescript/ts-reset": "^0.
|
|
76
|
+
"@tailwindcss/postcss": "^4.2.2",
|
|
77
|
+
"@total-typescript/ts-reset": "^0.6.1",
|
|
78
78
|
"@types/fs-extra": "^11.0.4",
|
|
79
79
|
"@types/gradient-string": "^1.1.6",
|
|
80
|
-
"@types/node": "^
|
|
81
|
-
"better-auth": "^1.
|
|
82
|
-
"drizzle-kit": "^0.31.
|
|
83
|
-
"drizzle-orm": "^0.
|
|
84
|
-
"mysql2": "^3.
|
|
85
|
-
"next": "^
|
|
86
|
-
"next-auth": "^4.24.
|
|
87
|
-
"postgres": "^3.4.
|
|
88
|
-
"react": "^19.2.
|
|
89
|
-
"react-dom": "^19.2.
|
|
80
|
+
"@types/node": "^25.5.0",
|
|
81
|
+
"better-auth": "^1.5.6",
|
|
82
|
+
"drizzle-kit": "^0.31.10",
|
|
83
|
+
"drizzle-orm": "^0.45.1",
|
|
84
|
+
"mysql2": "^3.20.0",
|
|
85
|
+
"next": "^16.2.1",
|
|
86
|
+
"next-auth": "^4.24.13",
|
|
87
|
+
"postgres": "^3.4.8",
|
|
88
|
+
"react": "^19.2.4",
|
|
89
|
+
"react-dom": "^19.2.4",
|
|
90
90
|
"superjson": "^2.2.6",
|
|
91
|
-
"tailwindcss": "^4.
|
|
91
|
+
"tailwindcss": "^4.2.2",
|
|
92
92
|
"tsup": "^8.5.1",
|
|
93
|
-
"type-fest": "^5.
|
|
94
|
-
"typescript": "^
|
|
95
|
-
"zod": "^3.
|
|
93
|
+
"type-fest": "^5.5.0",
|
|
94
|
+
"typescript": "^6.0.2",
|
|
95
|
+
"zod": "^4.3.6"
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -25,35 +25,35 @@
|
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@next/third-parties": "^16.
|
|
28
|
+
"@next/third-parties": "^16.2.1",
|
|
29
29
|
"clsx": "^2.1.1",
|
|
30
|
-
"framer-motion": "^12.
|
|
30
|
+
"framer-motion": "^12.38.0",
|
|
31
31
|
"husky": "^9.1.7",
|
|
32
|
-
"lint-staged": "^16.
|
|
33
|
-
"next": "^16.
|
|
34
|
-
"react": "^19.2.
|
|
35
|
-
"react-dom": "^19.2.
|
|
36
|
-
"schema-dts": "^
|
|
32
|
+
"lint-staged": "^16.4.0",
|
|
33
|
+
"next": "^16.2.1",
|
|
34
|
+
"react": "^19.2.4",
|
|
35
|
+
"react-dom": "^19.2.4",
|
|
36
|
+
"schema-dts": "^2.0.0",
|
|
37
37
|
"sharp": "^0.34.5",
|
|
38
|
-
"tailwind-merge": "^3.
|
|
38
|
+
"tailwind-merge": "^3.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@biomejs/biome": "2.
|
|
42
|
-
"@commitlint/cli": "^20.
|
|
43
|
-
"@commitlint/config-conventional": "^20.
|
|
44
|
-
"@tailwindcss/postcss": "^4.
|
|
41
|
+
"@biomejs/biome": "2.4.8",
|
|
42
|
+
"@commitlint/cli": "^20.5.0",
|
|
43
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
44
|
+
"@tailwindcss/postcss": "^4.2.2",
|
|
45
45
|
"@testing-library/jest-dom": "^6.9.1",
|
|
46
|
-
"@testing-library/react": "^16.3.
|
|
46
|
+
"@testing-library/react": "^16.3.2",
|
|
47
47
|
"@testing-library/user-event": "^14.6.1",
|
|
48
48
|
"@types/jest": "^30.0.0",
|
|
49
|
-
"@types/node": "^25.0
|
|
50
|
-
"@types/react": "^19.2.
|
|
49
|
+
"@types/node": "^25.5.0",
|
|
50
|
+
"@types/react": "^19.2.14",
|
|
51
51
|
"@types/react-dom": "^19.2.3",
|
|
52
|
-
"autoprefixer": "^10.4.
|
|
53
|
-
"jest": "^30.
|
|
54
|
-
"jest-environment-jsdom": "^30.
|
|
55
|
-
"postcss": "^8.5.
|
|
56
|
-
"tailwindcss": "^4.
|
|
57
|
-
"typescript": "^
|
|
52
|
+
"autoprefixer": "^10.4.27",
|
|
53
|
+
"jest": "^30.3.0",
|
|
54
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
55
|
+
"postcss": "^8.5.8",
|
|
56
|
+
"tailwindcss": "^4.2.2",
|
|
57
|
+
"typescript": "^6.0.2"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -1,70 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let supabaseResponse = NextResponse.next({
|
|
6
|
-
request,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// With Fluid compute, don't put this client in a global environment
|
|
11
|
-
// variable. Always create a new one on each request.
|
|
12
|
-
const supabase = createServerClient(
|
|
13
|
-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
14
|
-
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
|
|
15
|
-
{
|
|
16
|
-
cookies: {
|
|
17
|
-
getAll() {
|
|
18
|
-
return request.cookies.getAll();
|
|
19
|
-
},
|
|
20
|
-
setAll(cookiesToSet) {
|
|
21
|
-
cookiesToSet.forEach(({ name, value }) =>
|
|
22
|
-
request.cookies.set(name, value),
|
|
23
|
-
);
|
|
24
|
-
supabaseResponse = NextResponse.next({
|
|
25
|
-
request,
|
|
26
|
-
});
|
|
27
|
-
cookiesToSet.forEach(({ name, value, options }) =>
|
|
28
|
-
supabaseResponse.cookies.set(name, value, options),
|
|
29
|
-
);
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// Do not run code between createServerClient and
|
|
36
|
-
// supabase.auth.getClaims(). A simple mistake could make it very hard to debug
|
|
37
|
-
// issues with users being randomly logged out.
|
|
38
|
-
|
|
39
|
-
// IMPORTANT: If you remove getClaims() and you use server-side rendering
|
|
40
|
-
// with the Supabase client, your users may be randomly logged out.
|
|
41
|
-
const { data } = await supabase.auth.getClaims();
|
|
42
|
-
const user = data?.claims;
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
request.nextUrl.pathname !== "/" &&
|
|
46
|
-
!user &&
|
|
47
|
-
!request.nextUrl.pathname.startsWith("/login") &&
|
|
48
|
-
!request.nextUrl.pathname.startsWith("/auth")
|
|
49
|
-
) {
|
|
50
|
-
// no user, potentially respond by redirecting the user to the login page
|
|
51
|
-
const url = request.nextUrl.clone();
|
|
52
|
-
url.pathname = "/auth/login";
|
|
53
|
-
return NextResponse.redirect(url);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// IMPORTANT: You *must* return the supabaseResponse object as it is.
|
|
57
|
-
// If you're creating a new response object with NextResponse.next() make sure to:
|
|
58
|
-
// 1. Pass the request in it, like so:
|
|
59
|
-
// const myNewResponse = NextResponse.next({ request })
|
|
60
|
-
// 2. Copy over the cookies, like so:
|
|
61
|
-
// myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())
|
|
62
|
-
// 3. Change the myNewResponse object to fit your needs, but avoid changing
|
|
63
|
-
// the cookies!
|
|
64
|
-
// 4. Finally:
|
|
65
|
-
// return myNewResponse
|
|
66
|
-
// If this is not done, you may be causing the browser and server to go out
|
|
67
|
-
// of sync and terminate the user's session prematurely!
|
|
68
|
-
|
|
69
|
-
return supabaseResponse;
|
|
1
|
+
import { type NextRequest } from "next/server"
|
|
2
|
+
import { updateSession } from "@/lib/supabase/proxy"
|
|
3
|
+
export async function proxy(request: NextRequest) {
|
|
4
|
+
return await updateSession(request)
|
|
70
5
|
}
|
|
6
|
+
export const config = {
|
|
7
|
+
matcher: [
|
|
8
|
+
/*
|
|
9
|
+
* Match all request paths except for the ones starting with:
|
|
10
|
+
* - _next/static (static files)
|
|
11
|
+
* - _next/image (image optimization files)
|
|
12
|
+
* - favicon.ico (favicon file)
|
|
13
|
+
* Feel free to modify this pattern to include more paths.
|
|
14
|
+
*/
|
|
15
|
+
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
|
|
16
|
+
],
|
|
17
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createServerClient } from '@supabase/ssr'
|
|
2
|
+
import { NextResponse, type NextRequest } from 'next/server'
|
|
3
|
+
|
|
4
|
+
export async function updateSession(request: NextRequest) {
|
|
5
|
+
let supabaseResponse = NextResponse.next({
|
|
6
|
+
request,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
// With Fluid compute, don't put this client in a global environment
|
|
10
|
+
// variable. Always create a new one on each request.
|
|
11
|
+
const supabase = createServerClient(
|
|
12
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
13
|
+
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
|
|
14
|
+
{
|
|
15
|
+
cookies: {
|
|
16
|
+
getAll() {
|
|
17
|
+
return request.cookies.getAll()
|
|
18
|
+
},
|
|
19
|
+
setAll(cookiesToSet) {
|
|
20
|
+
cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))
|
|
21
|
+
supabaseResponse = NextResponse.next({
|
|
22
|
+
request,
|
|
23
|
+
})
|
|
24
|
+
cookiesToSet.forEach(({ name, value, options }) => supabaseResponse.cookies.set(name, value, options))
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
// Do not run code between createServerClient and
|
|
31
|
+
// supabase.auth.getClaims(). A simple mistake could make it very hard to debug
|
|
32
|
+
// issues with users being randomly logged out.
|
|
33
|
+
|
|
34
|
+
// IMPORTANT: If you remove getClaims() and you use server-side rendering
|
|
35
|
+
// with the Supabase client, your users may be randomly logged out.
|
|
36
|
+
const { data } = await supabase.auth.getClaims()
|
|
37
|
+
|
|
38
|
+
const user = data?.claims
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
!user &&
|
|
42
|
+
!request.nextUrl.pathname.startsWith('/login') &&
|
|
43
|
+
!request.nextUrl.pathname.startsWith('/auth')
|
|
44
|
+
) {
|
|
45
|
+
// no user, potentially respond by redirecting the user to the login page
|
|
46
|
+
const url = request.nextUrl.clone()
|
|
47
|
+
url.pathname = '/login'
|
|
48
|
+
return NextResponse.redirect(url)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// IMPORTANT: You *must* return the supabaseResponse object as it is. If you're
|
|
52
|
+
// creating a new response object with NextResponse.next() make sure to:
|
|
53
|
+
// 1. Pass the request in it, like so:
|
|
54
|
+
// const myNewResponse = NextResponse.next({ request })
|
|
55
|
+
// 2. Copy over the cookies, like so:
|
|
56
|
+
// myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())
|
|
57
|
+
// 3. Change the myNewResponse object to fit your needs, but avoid changing
|
|
58
|
+
// the cookies!
|
|
59
|
+
// 4. Finally:
|
|
60
|
+
// return myNewResponse
|
|
61
|
+
// If this is not done, you may be causing the browser and server to go out
|
|
62
|
+
// of sync and terminate the user's session prematurely!
|
|
63
|
+
|
|
64
|
+
return supabaseResponse
|
|
65
|
+
}
|