next-ts-cli 1.0.14 → 1.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-ts-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Create production-ready web application with the Next.js",
5
5
  "author": "Daniele Rossino <daniele.rossino10@gmail.com>",
6
6
  "maintainers": [],
@@ -1,70 +1,17 @@
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
-
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
+ }