-
-
Notifications
You must be signed in to change notification settings - Fork 1k
docs(examples): add integrations-supabase
#2058
Conversation
βοΈ Deploy Preview for nuxt3-docs canceled. π¨ Explore the source changes: ac77c69 π Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61a4fa13e9ff33000865eb4f |
export default defineNuxtConfig({ | ||
publicRuntimeConfig: { | ||
supabase: { | ||
url: process.env.SUPABASE_URL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key shall be same as env name to allow overriding un runtime (and top level)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand, what feature does it bring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overriding env variables at runtime. Current config basically adds env on build-time to bundle. Check this:
// Allow override from process.env and deserialize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the purpose of changing these keys at runtime? Do you have an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is runtime config :) Changing config without need to rebuild
// Supabase needs to read from req.cookies | ||
req.cookies = useCookies(req) | ||
// Check authenticated user during SSR | ||
user.value = (await auth.api.getUserByCookie(req)).user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic can be handle on demand in composable without using a global plugin (unless global guard is the purpose)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well actually having it by default offers a lot of features directly (feature flags per user, redirects, etc).
But if Nuxt exposes a smarter way to cachify() the user to speed up the process that would be neat.
I need to time the time execution of the plugin.
Something that Nuxt itself should expose (through hooks) so we can display them in the devtools (performance tabs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure to understand what you mean but yes we can cache promise within a composable/context :)
req.cookies = useCookies(req) | ||
res.status = () => ({ json: () => ({}) }) | ||
|
||
supabase.auth.api.setAuthCookie(req, res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can also be handled in app namespace (ssr only) instead of adding an additional api route
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well actually when doing the login it needs to also call our server to store the cookie as secured. How to would want to handle it without calling back the server?
Or we need to have a saveSession() exposed from Nuxt to easily create HTTP only cookies for secured sessions experience from day 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we probaly need useSession
. My main point is that it can be in a composable and yet running in server-only to set secure cookie. This reduces boilerplate and allows logic working with rest of ssr context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to try the demo to understand, when using Supabase, you basically no need to create API routes.
So I don't see how you want to implement this without an API call to works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same server logic just in composable :) Will make refactor
integrations-supabase
|
||
## Development | ||
|
||
Start the development server on http://localhost:3000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start the development server on http://localhost:3000 | |
Start the development server on http://localhost:3000: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird to me to add the : at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think @danielroe ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This convention can also potentially make formatting issues. If we do decide to add :
, should use explicit markdown syntax for generated link or add a space after 3000
|
||
- `useSupabase()` composable | ||
- User sessions with SSR support | ||
- Handle auth changes (and removes the session) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest either of the following:
- Handles auth changes (and removes the session)
- Handling auth changes (and removing the session)
npx nuxi init nuxt3-app -t nuxt/framework/examples/integrations/supabase | ||
``` | ||
|
||
Make sure to install the dependencies and setup the `.env`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to install the dependencies and setup the `.env`. | |
Make sure to install the dependencies and setup the `.env`: |
This is so awesome. I've been trying to experiment with ways to try add SSR support to https://github.com/supabase-community/nuxt-supabase with no luck but I'll definitely take learnings here and work on a PR there. |
Thanks a lot for this code. It's very helpful. Could you add an example of how to query Supabase in a page, (other to the authenticated user) please?
I'm trying to use the useSupabase() composable to do that but I can't make it work. |
Finally moving this to a Nuxt module. nuxt-modules/supabase#8 |
β Type of change
π Description
This example showcases how to use Supabase with Nuxt.
Features
useSupabase()
composable