Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/roam-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ env:
jobs:
deploy:
runs-on: ubuntu-latest
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions apps/roam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@octokit/auth-app": "^7.1.4",
"@octokit/core": "^6.1.3",
"@repo/types": "*",
"@supabase/auth-js": "^2.70.0",
"@supabase/supabase-js": "^2.50.0",
"@tldraw/tldraw": "^2.0.0-alpha.12",
"@vercel/blob": "^0.27.0",
"contrast-color": "^1.0.1",
Expand Down
4 changes: 4 additions & 0 deletions apps/roam/scripts/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export const compile = ({
outdir,
bundle: true,
format,
define: {
SUPABASE_URL: JSON.stringify(process.env.SUPABASE_URL!),
SUPABASE_ANON_KEY: JSON.stringify(process.env.SUPABASE_ANON_KEY!)
},
sourcemap: process.env.NODE_ENV === "production" ? undefined : "inline",
minify: process.env.NODE_ENV === "production",
entryNames: out,
Expand Down
1 change: 0 additions & 1 deletion apps/roam/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"module": "ESNext",
"moduleResolution": "Node",
"forceConsistentCasingInFileNames": true,

"jsx": "react",
"noUncheckedIndexedAccess": false
}
Expand Down
14 changes: 14 additions & 0 deletions apps/website/app/utils/supabase/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createClient as createSupabaseClient } from "@supabase/supabase-js";
import { Database } from "@repo/database/types.gen.ts";

// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth

export const createClient = () => {
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;

if (!url || !key) {
throw new Error("Missing required Supabase environment variables");
}
return createSupabaseClient<Database, "public", Database["public"]>(url, key);
};
70 changes: 70 additions & 0 deletions apps/website/app/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createServerClient } from "@supabase/ssr";
import { NextResponse, type NextRequest } from "next/server";

// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth

export const updateSession = async (request: NextRequest) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maparent can you give an example of how / when this is to be used? I didn't see it in #238

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used yet; I was following the documented pattern in the url above.

Copy link
Contributor

@mdroidian mdroidian Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly scanned the URL but didn't explicitly see it's use, only the code. Do you have a sense of where we will use it in the future?

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;

if (!supabaseUrl || !supabaseKey) {
throw new Error("Missing required Supabase environment variables");
}

let supabaseResponse = NextResponse.next({ request });

const supabase = createServerClient(supabaseUrl, supabaseKey, {
cookies: {
getAll() {
return request.cookies.getAll();
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) =>
request.cookies.set(name, value),
);
supabaseResponse = NextResponse.next({
request,
});
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options),
);
},
},
});

// Do not run code between createServerClient and
// supabase.auth.getUser(). A simple mistake could make it very hard to debug
// issues with users being randomly logged out.

// IMPORTANT: DO NOT REMOVE auth.getUser()

const {
data: { user },
} = await supabase.auth.getUser();

if (
!user &&
!request.nextUrl.pathname.startsWith("/login") &&
!request.nextUrl.pathname.startsWith("/auth")
) {
// no user, potentially respond by redirecting the user to the login page
const url = request.nextUrl.clone();
url.pathname = "/auth/login";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this will be added in #238

return NextResponse.redirect(url);
}

// IMPORTANT: You *must* return the supabaseResponse object as it is.
// If you're creating a new response object with NextResponse.next() make sure to:
// 1. Pass the request in it, like so:
// const myNewResponse = NextResponse.next({ request })
// 2. Copy over the cookies, like so:
// myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())
// 3. Change the myNewResponse object to fit your needs, but avoid changing
// the cookies!
// 4. Finally:
// return myNewResponse
// If this is not done, you may be causing the browser and server to go out
// of sync and terminate the user's session prematurely!

return supabaseResponse;
};
2 changes: 2 additions & 0 deletions apps/website/app/utils/supabase/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";
import { Database } from "@repo/database/types.gen.ts";

// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth

export const createClient = async () => {
const cookieStore = await cookies();
const supabaseUrl = process.env.SUPABASE_URL;
Expand Down
1 change: 1 addition & 0 deletions apps/website/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"baseUrl": ".",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose for adding this? Or problem is this solving?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was necessary for the paths to work well in #238, and also for the eslint work in #246 . Probably not strictly needed here, but I guess I got tired of git surgery.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine, it is just helpful to add the context.

"paths": {
"~/*": ["./app/*"]
},
Expand Down
126 changes: 100 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"ui": "npx shadcn@latest"
},
"devDependencies": {
"@repo/tailwind-config": "*",
"@repo/eslint-config": "*",
"@repo/tailwind-config": "*",
"@repo/typescript-config": "*",
"@turbo/gen": "^1.12.4",
"@types/eslint": "^8.56.5",
Expand All @@ -34,6 +34,8 @@
"typescript": "5.5.4"
},
"dependencies": {
"@supabase/auth-ui-react": "0.4.7",
"@supabase/supabase-js": "^2.50.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.468.0",
Expand Down
14 changes: 14 additions & 0 deletions packages/ui/src/lib/supabase/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createClient as createSupabaseClient } from "@supabase/supabase-js";
import { Database } from "@repo/database/types.gen.ts";

declare const SUPABASE_URL: string;
declare const SUPABASE_ANON_KEY: string;

// Inspired by https://supabase.com/ui/docs/react/password-based-auth

export const createClient = () => {
return createSupabaseClient<Database, "public", Database["public"]>(
SUPABASE_URL,
SUPABASE_ANON_KEY,
);
};
Loading