-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5494190
commit 8aaf2a0
Showing
9 changed files
with
254 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ yarn-error.log* | |
|
||
# typescript | ||
*.tsbuildinfo | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Next.js 13 SSR | ||
// NOTE: This is experimental and used as research to understand how to support Next.js 13 in the future. | ||
// https://beta.nextjs.org/docs/data-fetching/fetching#example-fetch-and-use-in-client-components | ||
|
||
import { use } from 'react'; | ||
import { createClient } from '@supabase/supabase-js'; | ||
|
||
async function getData() { | ||
const supabase = createClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL as string, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string | ||
); | ||
|
||
const { | ||
data: { user } | ||
} = await supabase.auth.getUser(); | ||
const { data } = await supabase.from('products').select('*').limit(1); | ||
|
||
return { user, data }; | ||
} | ||
|
||
export default function Page() { | ||
const data = use(getData()); | ||
return <pre>{JSON.stringify(data, null, 2)}</pre>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Next.js 13 SSR | ||
// NOTE: This is experimental and used as research to understand how to support Next.js 13 in the future. | ||
|
||
import Link from 'next/link'; | ||
|
||
export default async function Page() { | ||
return ( | ||
<> | ||
<h1>Next.js 13 examples</h1> | ||
<ul> | ||
<li> | ||
fetch and use in Client Components [ | ||
<Link href={'/nextjs-13/client-component'}>example</Link> |{' '} | ||
<a href="https://beta.nextjs.org/docs/data-fetching/fetching#example-fetch-and-use-in-client-components"> | ||
docs | ||
</a> | ||
] | ||
</li> | ||
<li> | ||
Dynamic Data (used to be getServerSideProps) [ | ||
<Link href={'/nextjs-13/ssr'}>example</Link> |{' '} | ||
<a href="https://beta.nextjs.org/docs/data-fetching/fetching#dynamic-data"> | ||
docs | ||
</a> | ||
] | ||
</li> | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Next.js 13 SSR | ||
// NOTE: This is experimental and used as research to understand how to support Next.js 13 in the future. | ||
|
||
import { cookies, headers } from 'next/headers'; | ||
import { | ||
CookieOptions, | ||
createBrowserSupabaseClient as _createBrowserSupabaseClient, | ||
createServerSupabaseClient as _createServerSupabaseClient, | ||
ensureArray, | ||
filterCookies, | ||
serializeCookie | ||
} from '@supabase/auth-helpers-shared'; | ||
|
||
function createServerSupabaseClient< | ||
Database = any, | ||
SchemaName extends string & keyof Database = 'public' extends keyof Database | ||
? 'public' | ||
: string & keyof Database | ||
>({ | ||
cookieOptions | ||
}: { | ||
cookieOptions?: CookieOptions; | ||
} = {}) { | ||
if ( | ||
!process.env.NEXT_PUBLIC_SUPABASE_URL || | ||
!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY | ||
) { | ||
throw new Error( | ||
'NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY env variables are required!' | ||
); | ||
} | ||
|
||
return _createServerSupabaseClient<Database, SchemaName>({ | ||
supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL, | ||
supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, | ||
getRequestHeader: (key) => headers().get(key) ?? undefined, | ||
|
||
getCookie(name) { | ||
return cookies().get(name); | ||
}, | ||
setCookie(name, value, options) { | ||
// TODO: figure out how to access response object | ||
// const newSetCookies = filterCookies( | ||
// ensureArray(context.res.getHeader('set-cookie')?.toString() ?? []), | ||
// name | ||
// ); | ||
// const newSessionStr = serializeCookie(name, value, { | ||
// ...options, | ||
// // Allow supabase-js on the client to read the cookie as well | ||
// httpOnly: false | ||
// }); | ||
// context.res.setHeader('set-cookie', [...newSetCookies, newSessionStr]); | ||
}, | ||
options: { | ||
global: { | ||
// fetch // TODO: is this needed? | ||
} | ||
}, | ||
cookieOptions | ||
}); | ||
} | ||
|
||
// https://beta.nextjs.org/docs/data-fetching/fetching#segment-cache-configuration | ||
export const cache = 'no-store'; | ||
|
||
async function getData() { | ||
const supabase = createServerSupabaseClient(); | ||
const { | ||
data: { user } | ||
} = await supabase.auth.getUser(); | ||
const { data } = await supabase.from('users').select('*'); | ||
|
||
return { user, data }; | ||
} | ||
|
||
export default async function Page() { | ||
const data = await getData(); | ||
return <pre>{JSON.stringify(data, null, 2)}</pre>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
experimental: { | ||
appDir: true | ||
} | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.