-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EXPERIMENTAL] Next.js 13 app
directory example
#342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ yarn-error.log* | |
|
||
# typescript | ||
*.tsbuildinfo | ||
|
||
.vscode |
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> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Next.js 13 Client Component | ||
// 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>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Next.js 13 | ||
// 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> | ||
</> | ||
); | ||
} |
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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are read-only functions: https://beta.nextjs.org/docs/upgrade-guide#accessing-request-object But we're able to modify the res via middleware, see discussion here: #341 (comment) |
||
}, | ||
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>; | ||
} |
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Will this be a client component without
use client
?Edit: This is probably still in draft and you are probably working on it. Just thought this might have been missed.