Skip to content
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

refactor(frontend): Update Supabase and backend API management #9036

Merged
merged 10 commits into from
Dec 18, 2024

Conversation

kcze
Copy link
Contributor

@kcze kcze commented Dec 17, 2024

Currently there are random issues (logout, auth desync) and inconveniences with how Supabase and backend API works.
Resolves:

Changes 🏗️

This PR streamlines how the Supabase and backend API is used to fix current errors with auth, remove unnecessary code and make it easier to use Supabase and backend API.

  • Add getServerSupabase for server side that returns SupabaseClient.
  • Add Spinner component that is used for loading animation.
  • Remove redundant useUser, user is fetched in useSupabase already.
  • Replace most Supabase create*Client to getSupabaseServer and useSupabase.
  • Remove redundant AutoGPTServerAPI class and rename BaseAutoGPTServerAPI to BackendAPI and use it instead.
  • Remove SupabaseProvider context; supabase caches internally what's possible already.
  • Move useSupabase hook to its own file and update it.

Helpful table

Next.js usage Server Client
API new BackendAPI(); new BackendAPI();* or useBackendAPI()
Supabase getServerSupabase(); useSupabase();
user, user.role getServerUser();** useSupabase();

* BackendAPI automatically chooses correct Supabase client, so while it's recommended to use useBackendAPI(), it's ok to use new BackendAPI(); in client components and even memoize it: useMemo(() => new BackendAPI(), []).

** The reason user isn't returned in getServerSupabase is because it forces async fetch but creating supabase doesn't, so it'd force getServerSupabase to be async or return { supabase: SupabaseClient, user: Promise<User> | null }. For the same reason useSupabase provides access to supabase immediately but user may be loading, so there's isUserLoading provided as well.

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • ...
Example test plan
  • Create from scratch and execute an agent with at least 3 blocks
  • Import an agent from file upload, and confirm it executes correctly
  • Upload agent to marketplace
  • Import an agent from marketplace and confirm it executes correctly
  • Edit an agent from monitor, and confirm it executes correctly

For configuration changes:

  • .env.example is updated or already compatible with my changes
  • docker-compose.yml is updated or already compatible with my changes
  • I have included a list of my configuration changes in the PR description (under Changes)
Examples of configuration changes
  • Changing ports
  • Adding new services that need to communicate with each other
  • Secrets or environment variable changes
  • New or infrastructure changes such as databases

@github-actions github-actions bot added platform/frontend AutoGPT Platform - Front end platform/backend AutoGPT Platform - Back end labels Dec 17, 2024
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit 679b619
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/6762966dbdb384000865796b

Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 679b619
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/6762966db537c100086b0731

@kcze kcze marked this pull request as ready for review December 17, 2024 16:16
@kcze kcze requested a review from a team as a code owner December 17, 2024 16:16
aarushik93
aarushik93 previously approved these changes Dec 17, 2024
@kcze kcze removed the request for review from majdyz December 17, 2024 21:40
@ntindle ntindle enabled auto-merge December 17, 2024 22:08
@ntindle ntindle added this pull request to the merge queue Dec 18, 2024
Merged via the queue into dev with commit 6ec2bac Dec 18, 2024
20 checks passed
@ntindle ntindle deleted the kpczerwinski/open-2214-fix-supabase-auth-sync-issues branch December 18, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/backend AutoGPT Platform - Back end platform/frontend AutoGPT Platform - Front end size/xl
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants