Skip to content

Commit 0532f8a

Browse files
committed
Address review comments
1 parent 7535386 commit 0532f8a

File tree

13 files changed

+292
-206
lines changed

13 files changed

+292
-206
lines changed

dev-packages/e2e-tests/test-applications/supabase-nextjs/lib/initSupabaseAdmin.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const NEXT_PUBLIC_SUPABASE_URL = 'http://localhost:54321';
66
const SUPABASE_SERVICE_ROLE_KEY =
77
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU';
88

9-
export const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
10-
auth: {
11-
persistSession: false,
12-
autoRefreshToken: false,
13-
detectSessionInUrl: false,
14-
},
15-
});
9+
export const getSupabaseClient = () => {
10+
const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
11+
auth: {
12+
persistSession: false,
13+
autoRefreshToken: false,
14+
detectSessionInUrl: false,
15+
},
16+
});
1617

17-
Sentry.addIntegration(
18-
Sentry.supabaseIntegration(supabaseClient),
19-
);
18+
Sentry.addIntegration(Sentry.supabaseIntegration(supabaseClient));
19+
20+
return supabaseClient;
21+
};

dev-packages/e2e-tests/test-applications/supabase-nextjs/lib/initSupabaseAnon.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const NEXT_PUBLIC_SUPABASE_URL = 'http://localhost:54321';
66
const NEXT_PUBLIC_SUPABASE_ANON_KEY =
77
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4cGxvcmV0ZXN0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2';
88

9-
export const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY);
9+
export const getSupabaseClient = () => {
10+
const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY);
11+
Sentry.addIntegration(Sentry.supabaseIntegration(supabaseClient));
1012

11-
Sentry.addIntegration(Sentry.supabaseIntegration(supabaseClient));
13+
return supabaseClient;
14+
};

dev-packages/e2e-tests/test-applications/supabase-nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "next build",
88
"start": "next start",
99
"clean": "npx rimraf node_modules pnpm-lock.yaml .next",
10-
"start-local-supabase": "supabase init --force --workdir . && supabase start -o env",
10+
"start-local-supabase": "supabase init --force --workdir . && supabase start -o env && supabase db reset",
1111
"test:prod": "TEST_ENV=production playwright test",
1212
"test:build": "pnpm install && pnpm start-local-supabase && pnpm build",
1313
"test:assert": "pnpm test:prod"

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/_app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { supabaseClient } from '@/lib/initSupabaseAnon'
1+
import { getSupabaseClient } from '@/lib/initSupabaseAnon'
22
import { SessionContextProvider } from '@supabase/auth-helpers-react'
33
import type { AppProps } from 'next/app'
44

5+
const supabaseClient = getSupabaseClient()
6+
57
export default function App({ Component, pageProps }: AppProps) {
68
return (
79
<SessionContextProvider supabaseClient={supabaseClient}>

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/api/add-todo-entry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
21
import type { NextApiRequest, NextApiResponse } from 'next';
3-
import { supabaseClient } from '@/lib/initSupabaseAdmin';
2+
import { getSupabaseClient } from '@/lib/initSupabaseAdmin';
43

54
type Data = {
65
data: any;
76
error: any;
87
};
98

9+
const supabaseClient = getSupabaseClient();
10+
1011
async function login() {
1112
const { data, error } = await supabaseClient.auth.signInWithPassword({
1213

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/api/create-test-user.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
21
import type { NextApiRequest, NextApiResponse } from 'next';
3-
import { supabaseClient } from '@/lib/initSupabaseAdmin';
2+
import { getSupabaseClient } from '@/lib/initSupabaseAdmin';
3+
import * as Sentry from '@sentry/nextjs';
44

55
type Data = {
66
data: any;
77
error: any;
88
};
99

10-
async function deleteExistingUsers() {
11-
const { data: { users }, error } = await supabaseClient.auth.admin.listUsers()
12-
13-
for (const user of users) {
14-
const { error } = await supabaseClient.auth.admin.deleteUser(user.id, true);
15-
if (error) console.log('error', error);
16-
}
17-
}
10+
const supabaseClient = getSupabaseClient();
1811

1912
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
20-
await deleteExistingUsers();
21-
13+
// Note for test usage
14+
// This only works once in tests as it will error if the user already exists
15+
// So this should be called only once before all tests to create the user
2216
const { data, error } = await supabaseClient.auth.admin.createUser({
2317
2418
password: 'sentry.test',
2519
email_confirm: true,
2620
});
2721

22+
if (error) {
23+
console.warn('ERROR', error);
24+
}
25+
2826
res.status(200).json({
2927
data,
3028
error,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { NextApiRequest, NextApiResponse } from 'next';
2+
import { getSupabaseClient } from '@/lib/initSupabaseAdmin';
3+
import * as Sentry from '@sentry/nextjs';
4+
5+
type Data = {
6+
data: any;
7+
error: any;
8+
};
9+
10+
const supabaseClient = getSupabaseClient();
11+
12+
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
13+
const { data, error } = await supabaseClient.auth.admin.listUsers();
14+
15+
if (error) {
16+
console.warn('ERROR', error);
17+
}
18+
19+
res.status(200).json({
20+
data,
21+
error,
22+
});
23+
}

dev-packages/e2e-tests/test-applications/supabase-nextjs/sentry.server.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The config you add here will be used whenever the server handles a request.
33
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
44

5-
import * as Sentry from "@sentry/nextjs";
5+
import * as Sentry from '@sentry/nextjs';
66

77
Sentry.init({
88
dsn: 'https://[email protected]/1337',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TRUNCATE auth.users CASCADE;
2+
TRUNCATE auth.identities CASCADE;

dev-packages/e2e-tests/test-applications/supabase-nextjs/tests/client.performance.test.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)