diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index bb94e1fe..55deb678 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,6 +4,7 @@ on:
push:
branches:
- main
+ - next
workflow_dispatch:
jobs:
diff --git a/examples/nextjs/db_types.ts b/examples/nextjs/db_types.ts
new file mode 100644
index 00000000..f196c90d
--- /dev/null
+++ b/examples/nextjs/db_types.ts
@@ -0,0 +1,118 @@
+export type Json =
+ | string
+ | number
+ | boolean
+ | null
+ | { [key: string]: Json }
+ | Json[];
+
+export interface Database {
+ public: {
+ Tables: {
+ partners: {
+ Row: {
+ id: number;
+ slug: string;
+ type: Database['public']['Enums']['partner_type'];
+ category: string;
+ developer: string;
+ title: string;
+ description: string;
+ logo: string;
+ images: string[];
+ video: string;
+ overview: string;
+ website: string;
+ docs: string;
+ approved: boolean;
+ };
+ Insert: {
+ id?: number;
+ slug?: string;
+ type?: Database['public']['Enums']['partner_type'];
+ category?: string;
+ developer?: string;
+ title?: string;
+ description?: string;
+ logo?: string;
+ images?: string[];
+ video?: string;
+ overview?: string;
+ website?: string;
+ docs?: string;
+ approved?: boolean;
+ };
+ Update: {
+ id?: number;
+ slug?: string;
+ type?: Database['public']['Enums']['partner_type'];
+ category?: string;
+ developer?: string;
+ title?: string;
+ description?: string;
+ logo?: string;
+ images?: string[];
+ video?: string;
+ overview?: string;
+ website?: string;
+ docs?: string;
+ approved?: boolean;
+ };
+ };
+ partner_contacts: {
+ Row: {
+ id: number;
+ type: Database['public']['Enums']['partner_type'];
+ company: string;
+ country: string;
+ details?: string;
+ email: string;
+ first: string;
+ last: string;
+ phone?: string;
+ size?: number;
+ title?: string;
+ website: string;
+ };
+ Insert: {
+ id?: number;
+ type?: Database['public']['Enums']['partner_type'];
+ company?: string;
+ country?: string;
+ details?: string;
+ email?: string;
+ first?: string;
+ last?: string;
+ phone?: string;
+ size?: number;
+ title?: string;
+ website?: string;
+ };
+ Update: {
+ id?: number;
+ type?: Database['public']['Enums']['partner_type'];
+ company?: string;
+ country?: string;
+ details?: string;
+ email?: string;
+ first?: string;
+ last?: string;
+ phone?: string;
+ size?: number;
+ title?: string;
+ website?: string;
+ };
+ };
+ };
+ Views: {};
+ Functions: {
+ derive_label_sort_from_label: {
+ Args: { label: string };
+ Returns: string;
+ };
+ };
+ Enums: {
+ partner_type: 'technology' | 'expert';
+ };
+ };
+}
diff --git a/examples/nextjs/middleware.ts b/examples/nextjs/middleware.ts
index 56bb9c23..dd0bd52f 100644
--- a/examples/nextjs/middleware.ts
+++ b/examples/nextjs/middleware.ts
@@ -1,13 +1,15 @@
import { withMiddlewareAuth } from '@supabase/auth-helpers-nextjs';
export const middleware = withMiddlewareAuth({
- redirectTo: '/login',
+ redirectTo: '/',
authGuard: {
- isPermitted: async (user) => user.email?.endsWith('@example.com') ?? false,
+ isPermitted: async (user) => {
+ return user.email?.endsWith('@gmail.com') ?? false;
+ },
redirectTo: '/insufficient-permissions'
}
});
export const config = {
- matcher: ['/middleware-protected/:path*']
+ matcher: '/middleware-protected'
};
diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json
index df8e6dc3..fdc6bee4 100644
--- a/examples/nextjs/package.json
+++ b/examples/nextjs/package.json
@@ -12,6 +12,7 @@
"dependencies": {
"@supabase/auth-helpers-nextjs": "workspace:*",
"@supabase/auth-helpers-react": "workspace:*",
+ "@supabase/auth-ui-react": "^0.1.8",
"next": "^12.2.5",
"react": "17.0.2",
"react-dom": "17.0.2"
diff --git a/examples/nextjs/pages/_app.tsx b/examples/nextjs/pages/_app.tsx
index 307b37f9..3dab1779 100644
--- a/examples/nextjs/pages/_app.tsx
+++ b/examples/nextjs/pages/_app.tsx
@@ -1,17 +1,33 @@
-import '../styles/globals.css';
+import { useRouter } from 'next/router';
+import { createBrowserSupabaseClient } from '@supabase/auth-helpers-nextjs';
+import { SessionContextProvider } from '@supabase/auth-helpers-react';
import type { AppProps } from 'next/app';
-import { UserProvider } from '@supabase/auth-helpers-react';
-import { supabaseClient } from '@supabase/auth-helpers-nextjs';
-import Link from 'next/link';
+import { useState } from 'react';
+import { Database } from '../db_types';
+import '../styles/globals.css';
function MyApp({ Component, pageProps }: AppProps) {
+ const router = useRouter();
+ const [supabaseClient] = useState(() =>
+ createBrowserSupabaseClient {error.message}Loading...
: Loaded!
}
+
user:
-{JSON.stringify(user, null, 2)}+
{JSON.stringify(session, null, 2)}
client-side data fetching with RLS
{JSON.stringify(data, null, 2)}> diff --git a/examples/nextjs/pages/middleware-protected/index.tsx b/examples/nextjs/pages/middleware-protected.tsx similarity index 100% rename from examples/nextjs/pages/middleware-protected/index.tsx rename to examples/nextjs/pages/middleware-protected.tsx diff --git a/examples/nextjs/pages/profile.tsx b/examples/nextjs/pages/profile.tsx index 5610f775..5e38bfb2 100644 --- a/examples/nextjs/pages/profile.tsx +++ b/examples/nextjs/pages/profile.tsx @@ -1,15 +1,14 @@ // pages/profile.js -import { withPageAuth, User } from '@supabase/auth-helpers-nextjs'; +import { withPageAuth } from '@supabase/auth-helpers-nextjs'; +import { useSessionContext } from '@supabase/auth-helpers-react'; import Link from 'next/link'; -export default function Profile({ - user, - error -}: { - user: User; - error: string; -}) { - if (user) +export default function Profile() { + const { error, session } = useSessionContext(); + + if (session?.user) { + const { user } = session; + return ( <>
@@ -20,6 +19,8 @@ export default function Profile({
{JSON.stringify(user, null, 2)}> ); + } + return
{error}
; } diff --git a/examples/nextjs/pages/protected-page.tsx b/examples/nextjs/pages/protected-page.tsx index 696e4dac..d3cc5aa4 100644 --- a/examples/nextjs/pages/protected-page.tsx +++ b/examples/nextjs/pages/protected-page.tsx @@ -1,27 +1,19 @@ // pages/protected-page.js -import { - User, - withPageAuth, - supabaseServerClient -} from '@supabase/auth-helpers-nextjs'; +import { withPageAuth } from '@supabase/auth-helpers-nextjs'; +import { useSessionContext } from '@supabase/auth-helpers-react'; import Link from 'next/link'; -export default function ProtectedPage({ - user, - data, - error -}: { - user: User; - data: any; - error: string; -}) { +export default function ProtectedPage({ data }: { data: any }) { + const { error, session } = useSessionContext(); + const user = session?.user; + return ( <>[Home] | [ withPageAuth]
-server-side fetched data with RLS:
{JSON.stringify(data, null, 2)}
{error}
@@ -33,9 +25,10 @@ export default function ProtectedPage({ export const getServerSideProps = withPageAuth({ redirectTo: '/', - async getServerSideProps(ctx) { + async getServerSideProps(ctx, supabase) { // Run queries with RLS on the server - const { data } = await supabaseServerClient(ctx).from('test').select('*'); - return { props: { data } }; + const { data } = await supabase.from('test').select('*'); + + return { props: { data: data ?? [] } }; } }); diff --git a/examples/sveltekit-email-password/package.json b/examples/sveltekit-email-password/package.json index 35db8093..4b439c23 100644 --- a/examples/sveltekit-email-password/package.json +++ b/examples/sveltekit-email-password/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@sveltejs/adapter-auto": "next", - "@sveltejs/kit": "1.0.0-next.499", + "@sveltejs/kit": "1.0.0-next.504", "@typescript-eslint/eslint-plugin": "^5.10.1", "@typescript-eslint/parser": "^5.10.1", "eslint": "^7.32.0", @@ -34,6 +34,6 @@ "type": "module", "dependencies": { "@supabase/auth-helpers-sveltekit": "workspace:*", - "@supabase/supabase-js": "^1.35.3" + "@supabase/supabase-js": "2.0.0" } } diff --git a/examples/sveltekit-email-password/src/app.d.ts b/examples/sveltekit-email-password/src/app.d.ts index a06438fb..0bb5755b 100644 --- a/examples/sveltekit-email-password/src/app.d.ts +++ b/examples/sveltekit-email-password/src/app.d.ts @@ -4,11 +4,9 @@ // for information about these interfaces // and what to do when importing types declare namespace App { - interface Locals { - session: import('@supabase/auth-helpers-sveltekit').SupabaseSession; - } + // interface Locals {} interface PageData { - session: import('@supabase/auth-helpers-sveltekit').SupabaseSession; + session: import('@supabase/supabase-js').Session | null; } // interface Error {} // interface Platform {} diff --git a/examples/sveltekit-email-password/src/hooks.client.ts b/examples/sveltekit-email-password/src/hooks.client.ts new file mode 100644 index 00000000..b99dd39e --- /dev/null +++ b/examples/sveltekit-email-password/src/hooks.client.ts @@ -0,0 +1 @@ +import '$lib/db'; diff --git a/examples/sveltekit-email-password/src/hooks.server.ts b/examples/sveltekit-email-password/src/hooks.server.ts index 9a754db1..b99dd39e 100644 --- a/examples/sveltekit-email-password/src/hooks.server.ts +++ b/examples/sveltekit-email-password/src/hooks.server.ts @@ -1,4 +1 @@ import '$lib/db'; -import { auth } from '@supabase/auth-helpers-sveltekit/server'; - -export const handle = auth(); diff --git a/examples/sveltekit-email-password/src/lib/db.ts b/examples/sveltekit-email-password/src/lib/db.ts index 7920a2fc..d1b758f1 100644 --- a/examples/sveltekit-email-password/src/lib/db.ts +++ b/examples/sveltekit-email-password/src/lib/db.ts @@ -1,16 +1,7 @@ -import { createClient } from '@supabase/supabase-js'; -import { setupSupabaseHelpers } from '@supabase/auth-helpers-sveltekit'; +import { createClient } from '@supabase/auth-helpers-sveltekit'; import { env } from '$env/dynamic/public'; -import { dev } from '$app/environment'; -export const supabaseClient = createClient(env.PUBLIC_SUPABASE_URL, env.PUBLIC_SUPABASE_ANON_KEY, { - persistSession: false, - autoRefreshToken: false -}); - -setupSupabaseHelpers({ - supabaseClient, - cookieOptions: { - secure: !dev - } -}); +export const supabaseClient = createClient( + env.PUBLIC_SUPABASE_URL ?? '', + env.PUBLIC_SUPABASE_ANON_KEY ?? '' +); diff --git a/examples/sveltekit-email-password/src/lib/types.ts b/examples/sveltekit-email-password/src/lib/types.ts deleted file mode 100644 index a3c3d4e4..00000000 --- a/examples/sveltekit-email-password/src/lib/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface TestTable { - id: string; - created_at: string; -} diff --git a/examples/sveltekit-email-password/src/routes/(app)/+layout.svelte b/examples/sveltekit-email-password/src/routes/(app)/+layout.svelte index 8c8ce39e..fa0c3e36 100644 --- a/examples/sveltekit-email-password/src/routes/(app)/+layout.svelte +++ b/examples/sveltekit-email-password/src/routes/(app)/+layout.svelte @@ -1,12 +1,19 @@ @@ -21,9 +28,9 @@ Supabase Auth Helpers Demo diff --git a/examples/sveltekit-email-password/src/routes/(app)/+page.server.ts b/examples/sveltekit-email-password/src/routes/(app)/+page.server.ts index 1ea0573f..8d0ca055 100644 --- a/examples/sveltekit-email-password/src/routes/(app)/+page.server.ts +++ b/examples/sveltekit-email-password/src/routes/(app)/+page.server.ts @@ -1,10 +1,12 @@ -import { supabaseClient } from '$lib/db'; -import { invalid, redirect } from '@sveltejs/kit'; +import { getSupabase } from '@supabase/auth-helpers-sveltekit'; +import { AuthApiError } from '@supabase/supabase-js'; +import { invalid, redirect, type ValidationError } from '@sveltejs/kit'; import type { Actions } from './$types'; -import { saveSession } from '@supabase/auth-helpers-sveltekit/server'; export const actions: Actions = { - async default({ request, cookies, url }) { + async default(event): Promise