Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jun 25, 2025

There are many branches (notably #238, which may be broken in three before merge; and an upcoming branch for ENG-420 which I need to base on both this one and #245) that assume access to supabase infrastructure in the front-end; I just wanted to isolate the infrastructure work from the ui work in the ENG-373 branch, so those other branches build on it.

An unfortunate consequence of this is that turbo now expects SUPABASE_URL and SUPABASE_ANON_KEY to be defined. We will all need to update our .env accordingly. This should be fine with vercel and github actions.

Note: There are a few non-obvious choices, such as putting the client code in the ui, which I think will benefit obsidian in the longer term.

Summary by CodeRabbit

  • New Features

    • Added utility functions for creating and managing Supabase clients in both the website and UI packages.
    • Introduced session management middleware for user authentication with Supabase in the website app.
  • Chores

    • Updated environment variable handling across build, development, deployment, and CI workflows to support Supabase integration.
    • Added Supabase-related dependencies to project packages.
    • Enhanced TypeScript configurations with new path aliases for simplified imports.

@linear
Copy link

linear bot commented Jun 25, 2025

@supabase
Copy link

supabase bot commented Jun 25, 2025

This pull request has been ignored for the connected project plzkmulvmuhdpcmnyrhm because there are no changes detected in projects/database/supabase/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

📝 Walkthrough

Walkthrough

The changes introduce Supabase integration across multiple project areas. Environment variables for Supabase are added to GitHub Actions, Turbo, and build processes. Supabase client creation utilities are implemented in both the UI and website packages. TypeScript path aliases are updated to simplify imports, and new Supabase dependencies are added to relevant package manifests.

Changes

File(s) Change Summary
.github/workflows/roam-pr.yaml, turbo.json Added SUPABASE_URL and SUPABASE_ANON_KEY to environment variable lists in workflow and build tool configurations.
apps/roam/package.json, packages/ui/package.json Added Supabase dependencies and reordered some devDependencies.
apps/roam/scripts/compile.ts Injected SUPABASE_URL and SUPABASE_ANON_KEY as compile-time constants using esbuild's define option.
apps/roam/tsconfig.json, apps/website/tsconfig.json Added/updated TypeScript path aliases for simplified module imports.
apps/website/app/utils/supabase/client.ts, packages/ui/src/lib/supabase/client.ts Introduced createClient utility functions for initializing typed Supabase clients.
apps/website/app/utils/supabase/middleware.ts Added updateSession middleware for Supabase session management and authentication redirects in Next.js.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NextRequest
    participant updateSession
    participant SupabaseClient
    participant SupabaseAuth
    participant NextResponse

    User->>NextRequest: Sends HTTP request
    NextRequest->>updateSession: Passes request
    updateSession->>SupabaseClient: Create client with env vars
    updateSession->>SupabaseAuth: supabase.auth.getUser()
    alt User not authenticated and not on login route
        updateSession->>NextResponse: Redirect to login
    else User authenticated or on login route
        updateSession->>NextResponse: Return original response
    end
Loading
sequenceDiagram
    participant AppModule
    participant createClient
    participant SupabaseClient

    AppModule->>createClient: Call with env vars
    createClient->>SupabaseClient: Initialize with URL and anon key
    createClient-->>AppModule: Return Supabase client instance
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🔭 Outside diff range comments (2)
turbo.json (2)

30-31: Remove duplicate environment variables in dev task.

SUPABASE_URL and SUPABASE_ANON_KEY are listed twice in the dev task's passThroughEnv array (lines 30-31 and 37-38).

 "dev": {
   "passThroughEnv": [
     "OBSIDIAN_PLUGIN_PATH",
     "NODE_ENV",
-    "SUPABASE_URL",
-    "SUPABASE_ANON_KEY",
     "SUPABASE_SERVICE_ROLE_KEY",
     "POSTGRES_URL",
     "OPENAI_API_KEY",
     "ANTHROPIC_API_KEY",
     "GEMINI_API_KEY",
     "SUPABASE_ANON_KEY",
     "SUPABASE_URL"
   ],

Also applies to: 37-38


55-56: Remove duplicate environment variables in deploy task.

Similar to the dev task, SUPABASE_URL and SUPABASE_ANON_KEY are duplicated in the deploy task's passThroughEnv array.

 "deploy": {
   "passThroughEnv": [
     "BLOB_READ_WRITE_TOKEN",
     "GITHUB_REF_NAME",
     "GITHUB_HEAD_REF",
     "NODE_ENV",
     "SUPABASE_PROJECT_ID",
     "SUPABASE_DB_PASSWORD",
     "SUPABASE_ACCESS_TOKEN",
-    "SUPABASE_URL",
-    "SUPABASE_ANON_KEY",
     "SUPABASE_SERVICE_ROLE_KEY",
     "POSTGRES_URL",
     "OPENAI_API_KEY",
     "ANTHROPIC_API_KEY",
     "GEMINI_API_KEY",
     "SUPABASE_ANON_KEY",
     "SUPABASE_URL"
   ]
 }

Also applies to: 62-63

🧹 Nitpick comments (5)
packages/ui/package.json (2)

26-26: Re-ordering only? Consider trimming noise in future bumps.

The move of "@repo/tailwind-config" below "@repo/eslint-config" is benign but adds churn to the diff. Next time, defer cosmetic re-ordering to a dedicated “house-keeping” PR to keep functional changes focused.


37-38: Duplicate Supabase deps across workspaces – hoist or pin identically.

@supabase/supabase-js is now declared here while the Roam app also depends on ^2.50.0. If either package drifts, the monorepo may resolve two copies and inflate bundle size (especially with ESM tree-shaking disabled).

Recommendation:

-    "@supabase/auth-ui-react": "0.4.7",
-    "@supabase/supabase-js": "^2.50.0",
+    "@supabase/auth-ui-react": "0.4.7",
+    "@supabase/supabase-js": "^2.50.0"      # keep but
+# TODO: add both to the repo-root package.json “resolutions” / “overrides”
+# OR move them to the top-level “dependencies” to guarantee single-instance hoisting.

Also consider using a caret or an exact version for both auth-ui-react and supabase-js consistently to avoid mismatched peer ranges.

apps/roam/package.json (1)

31-32: Version drift risk with Supabase packages.

@supabase/supabase-js is declared here as ^2.50.0, identical to the UI package – good.
However, Roam uses the low-level @supabase/auth-js whereas UI uses @supabase/auth-ui-react. Confirm that both libraries will never be bundled together in the same runtime (e.g. website + iframe), otherwise expect ~80 kB extra. If duplication is unavoidable, centralise them at the repo root to guarantee a single copy.

apps/website/app/utils/supabase/client.ts (1)

1-1: Consider consistent quote usage.

Mixed quote styles are used across files (single quotes here vs double quotes in other files). Consider standardizing to maintain consistency.

apps/website/app/utils/supabase/middleware.ts (1)

40-49: Consider more flexible redirect configuration.

The hardcoded redirect paths and login URL could benefit from configuration to make the middleware more reusable.

Consider extracting the configuration:

+const PROTECTED_PATHS_CONFIG = {
+  excludePatterns: ['/login', '/auth'],
+  loginPath: '/auth/login'
+};
+
 if (
   !user &&
-  !request.nextUrl.pathname.startsWith('/login') &&
-  !request.nextUrl.pathname.startsWith('/auth')
+  !PROTECTED_PATHS_CONFIG.excludePatterns.some(pattern => 
+    request.nextUrl.pathname.startsWith(pattern)
+  )
 ) {
   const url = request.nextUrl.clone()
-  url.pathname = '/auth/login'
+  url.pathname = PROTECTED_PATHS_CONFIG.loginPath
   return NextResponse.redirect(url)
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 385f9bb and bb62f2a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .github/workflows/roam-pr.yaml (1 hunks)
  • apps/roam/package.json (1 hunks)
  • apps/roam/scripts/compile.ts (1 hunks)
  • apps/roam/tsconfig.json (1 hunks)
  • apps/website/app/utils/supabase/client.ts (1 hunks)
  • apps/website/app/utils/supabase/middleware.ts (1 hunks)
  • apps/website/tsconfig.json (1 hunks)
  • packages/ui/package.json (2 hunks)
  • packages/ui/src/lib/supabase/client.ts (1 hunks)
  • turbo.json (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/website/app/utils/supabase/client.ts (2)
packages/ui/src/lib/supabase/client.ts (1)
  • createClient (7-12)
packages/database/types.gen.ts (1)
  • Database (9-814)
🔇 Additional comments (4)
apps/roam/tsconfig.json (1)

15-18: Path alias looks good – watch for overlap with upstream config.

The new ~/* and @repo/* aliases resolve correctly from apps/roam, but make sure they don't shadow identical aliases already provided by @repo/typescript-config/react-library.json. If duplication exists the compiler will silently ignore one of them.

packages/ui/src/lib/supabase/client.ts (2)

4-5: Verify global constants are properly injected.

The global constants SUPABASE_URL and SUPABASE_ANON_KEY are declared but their injection relies on the build configuration in apps/roam/scripts/compile.ts. Ensure the build process properly defines these constants to avoid runtime errors.


7-12: LGTM! Strongly typed Supabase client creation.

The function correctly creates a strongly typed Supabase client with proper generic parameters. The typing ensures type safety for database operations.

apps/website/app/utils/supabase/middleware.ts (1)

4-65: LGTM! Well-implemented Supabase SSR middleware.

The middleware correctly implements Supabase session management for Next.js SSR with proper cookie handling and authentication flow. The detailed comments are particularly helpful for understanding the critical aspects of the implementation.

@maparent maparent force-pushed the ENG-520-supabase-in-frontend branch from bb62f2a to 9cf8334 Compare June 25, 2025 22:27
@maparent maparent marked this pull request as ready for review June 25, 2025 22:30
@maparent maparent requested a review from mdroidian June 25, 2025 22:31
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

There are many branches that assume access to supabase infrastructure in the front-end

Could you give an example (link the file or even directly to the code as GitHub will highlight it or embed it) EG:

highlight from another PR
#238 (comment)

embedded

SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}

... ui work in the ENG-373 branch, so other branches can benefit from this infrastructure work, notably future ENG-420 work ...

Note: you can use the # in GitHub to link to other branches. This makes it easier for anyone else viewing this PR to navigate to what you are referencing. EG: #238

@maparent maparent force-pushed the ENG-520-supabase-in-frontend branch from 9cf8334 to 6cfbec9 Compare June 26, 2025 01:37
@maparent
Copy link
Collaborator Author

On PR references: I find using the PR numbers confusing, as I think of the task in terms of linear task numbers. I wish there were a good way to make short linear references in github. But yeah, I also see the value of hyperlinking of course. Just pointing out a cognitive overhead.

@maparent maparent force-pushed the ENG-520-supabase-in-frontend branch from 6cfbec9 to 93b7c94 Compare June 26, 2025 02:22
@maparent maparent requested a review from mdroidian June 26, 2025 02:25
@maparent
Copy link
Collaborator Author

sorry, went too fast in re-request, one aspect is missing: Will it work in obsidian? I don't know, and I don't know that part of the codebase enough to test it. But I checked that, as long as the variables as defined (my warning at the top of the PR), obsidian builds correctly. As for calling it, I see no reason why not, but we may need to add environment passthrough here and there. I think we can wait until we actually call it to check that.

@mdroidian
Copy link
Contributor

On PR references: I find using the PR numbers confusing, as I think of the task in terms of linear task numbers. I wish there were a good way to make short linear references in github. But yeah, I also see the value of hyperlinking of course. Just pointing out a cognitive overhead.

Because we are adding the linear id's in the PR titles, # will find these as well. In terms of linking directly to linear, Ctrl-C when you are in a linear task will copy a markdown friendly URL to paste anywhere.

@mdroidian
Copy link
Contributor

sorry, went too fast in re-request, one aspect is missing: Will it work in obsidian? I don't know, and I don't know that part of the codebase enough to test it. But I checked that, as long as the variables as defined (my warning at the top of the PR), obsidian builds correctly. As for calling it, I see no reason why not, but we may need to add environment passthrough here and there. I think we can wait until we actually call it to check that.

Ah, I was asking because I thought it was added for Obsidian:

Note: There are a few non-obvious choices, such as putting the client code in the ui, which I think will benefit obsidian in the longer term.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

A few clarifying questions/comments, but not blocking.

) {
// 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


// 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?

{
"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.

@linear
Copy link

linear bot commented Jun 26, 2025

@maparent maparent merged commit e9c68b0 into main Jun 26, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jun 26, 2025
@maparent maparent deleted the ENG-520-supabase-in-frontend branch June 26, 2025 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants