@floatingpixels/supabase-nuxt 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,9 +7,9 @@
7
7
 
8
8
  ## Features
9
9
 
10
- [@floatingpixels/supabase-nuxt](https://github.com/nuxt-modules/supabase) is a Nuxt module for first class integration with Supabase. It makes it easy to use Supabase authentication, database and realtime features in your Nuxt 3 application. Especially when using server-side rendering SSR, using Supabase can be tricky, this module takes care of the intricacies and lets you simply use the power of Supabase!
10
+ [@floatingpixels/supabase-nuxt](https://github.com/floatingpixels/supabase-nuxt) is a Nuxt module for first-class integration with Supabase. It makes it easy to use Supabase authentication, database and realtime features in your Nuxt 3 or Nuxt 4 application. Especially when using server-side rendering (SSR), using Supabase can be tricky, this module takes care of the intricacies and lets you simply use the power of Supabase!
11
11
 
12
- Checkout the [Nuxt 3](https://v3.nuxtjs.org) documentation and [Supabase](https://supabase.com) to learn more.
12
+ Check out the [Nuxt](https://nuxt.com/docs) documentation and [Supabase](https://supabase.com/docs) to learn more.
13
13
 
14
14
  ## Testing
15
15
 
@@ -37,14 +37,14 @@ export default defineNuxtConfig({
37
37
  })
38
38
  ```
39
39
 
40
- Add `SUPABASE_URL` and `SUPABASE_PUBLISHABLE_KEY` to `.env`:
40
+ Add `NUXT_PUBLIC_SUPABASE_URL` and `NUXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` to `.env`:
41
41
 
42
42
  ```zsh
43
43
  NUXT_PUBLIC_SUPABASE_URL="https://example.supabase.co"
44
44
  NUXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=""
45
45
  ```
46
46
 
47
- When dynamically setting the variables during in an environment, make sure to prefix the environment variables with `NUXT_PUBLIC_` in order to use `runtimeConfig`.
47
+ When dynamically setting the variables in an environment, make sure to prefix the public environment variables with `NUXT_PUBLIC_` in order to use `runtimeConfig`.
48
48
 
49
49
  The public keys are required to be set in the environment for the module to work. If the service role is needed, you should also set `NUXT_SUPABASE_SERVICE_ROLE_KEY` in the environment, which will be only available on the server side as a private runtime variable.
50
50
 
@@ -61,6 +61,8 @@ export default defineNuxtConfig({
61
61
  }
62
62
  ```
63
63
 
64
+ The module extends existing `runtimeConfig.public.supabase` and `runtimeConfig.supabase` values instead of replacing them. This lets explicit runtime config and `NUXT_*` environment overrides take precedence over module defaults.
65
+
64
66
  ### `url`
65
67
 
66
68
  Default: `process.env.NUXT_PUBLIC_SUPABASE_URL` (e.g.: `https://example.supabase.co`)
@@ -83,7 +85,7 @@ Supabase 'service role key', has super admin rights and can bypass your Row Leve
83
85
 
84
86
  Default: `false`
85
87
 
86
- Re-direct automatically to the configured login page if a non authenticated user is navigating to a page. When set to `true` a global middleware is used to check for a logged-in Supabase use on all non-excluded routes.
88
+ Re-direct automatically to the configured login page if a non authenticated user is navigating to a page. When set to `true` a global middleware is used to check for a logged-in Supabase user on all non-excluded routes.
87
89
 
88
90
  ### `redirectOptions`
89
91
 
@@ -169,9 +171,9 @@ When using e-mail authentication, a confirmation e-mail is sent to new users, an
169
171
 
170
172
  The confirmation route on your server is provided by this module, so you don't need to implement it yourself. It's available at `/auth/confirm`. It will automatically confirm the user and re-direct to the `redirect_to` route.
171
173
 
172
- If you want to customize the confirmation route, you can do so by creating a server route to handle the request, and point to it in your Supabase e-mail template. Your custom route will receive the `token_hash` and `type` URL parameters, and the `redirect_to` URL parameter if provided. You can use the `useSupabaseClient` composable to confirm the user and re-direct to the `next` route:
174
+ If you want to customize the confirmation route, you can do so by creating a server route to handle the request, and point to it in your Supabase e-mail template. Your custom route will receive the `token_hash` and `type` URL parameters, and the `redirect_to` URL parameter if provided. You can use the `supabaseServerClient` server helper to confirm the user and re-direct to the next route:
173
175
 
174
- > ⚠️ You can use the provided confirm route at `/supabase/confirm`, the implementation of a custom route is optional!
176
+ > ⚠️ You can use the provided confirm route at `/auth/confirm`, the implementation of a custom route is optional!
175
177
 
176
178
  ```ts [server/api/confirm.ts]
177
179
  import { EmailOtpType } from '@supabase/supabase-js'
@@ -278,7 +280,7 @@ This composable can be used to make requests to the Supabase API. It's auto-impo
278
280
 
279
281
  Please check [Supabase](https://supabase.com/docs/reference/javascript/select) documentation on how to fully use the Supabase client.
280
282
 
281
- Here is an example of fetching from the database using the Supabase client's `select` method with Nuxt 3 [useAsyncData](https://nuxt.com/docs/getting-started/data-fetching#useasyncdata).
283
+ Here is an example of fetching from the database using the Supabase client's `select` method with Nuxt's [useAsyncData](https://nuxt.com/docs/getting-started/data-fetching#useasyncdata).
282
284
 
283
285
  ```vue
284
286
  <script setup lang="ts">
@@ -356,7 +358,7 @@ const signInWithOAuth = async () => {
356
358
  const { error } = await supabase.auth.signInWithOAuth({
357
359
  provider: 'github',
358
360
  options: {
359
- redirectTo: 'http://localhost:3000/confirm',
361
+ redirectTo: 'http://localhost:3000/auth/callback',
360
362
  },
361
363
  })
362
364
  if (error) console.log(error)
@@ -395,7 +397,7 @@ Make requests with super admin rights to the Supabase API with the `supabaseServ
395
397
 
396
398
  It provides similar functionality as the `supabaseServerClient` but it provides a client with super admin rights that can bypass your [Row Level Security](https://supabase.com/docs/guides/auth/row-level-security).
397
399
 
398
- The client is initialized with the `SUPABASE_SERVICE_ROLE_KEY` you must have in your environment. Checkout the doc if you want to know more about [Supabase keys](https://supabase.com/docs/learn/auth-deep-dive/auth-deep-dive-jwts#jwts-in-supabase).
400
+ The client is initialized with the `NUXT_SUPABASE_SERVICE_ROLE_KEY` you must have in your environment. Check out the doc if you want to know more about [Supabase keys](https://supabase.com/docs/learn/auth-deep-dive/auth-deep-dive-jwts#jwts-in-supabase).
399
401
 
400
402
  > ⚠️ The service key gives admin access to your database, be careful to not expose it in your client side code or in your git repository.
401
403
 
@@ -405,7 +407,7 @@ In your server route use the `supabaseServiceRole` from `#supabase/server`.
405
407
  import { supabaseServiceRole } from '#supabase/server'
406
408
 
407
409
  export default eventHandler(async event => {
408
- const client = supabaseServiceRole(event)
410
+ const client = await supabaseServiceRole(event)
409
411
 
410
412
  const { data } = await client.from('rls-protected-table').select()
411
413
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">3.0.0"
6
6
  },
7
- "version": "0.6.1",
7
+ "version": "0.6.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addTypeTemplate, extendViteConfig } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addImportsDir, addTypeTemplate, extendViteConfig } from '@nuxt/kit';
2
+ import { defu } from 'defu';
2
3
 
3
4
  const module$1 = defineNuxtModule({
4
5
  meta: {
@@ -28,24 +29,36 @@ const module$1 = defineNuxtModule({
28
29
  },
29
30
  setup(options, nuxt) {
30
31
  const { resolve } = createResolver(import.meta.url);
31
- if (!process.env.NUXT_PUBLIC_SUPABASE_URL && !options.url) {
32
+ const publicSupabaseConfig = nuxt.options.runtimeConfig.public.supabase;
33
+ const supabaseConfig = nuxt.options.runtimeConfig.supabase;
34
+ if (!process.env.NUXT_PUBLIC_SUPABASE_URL && !options.url && !publicSupabaseConfig?.url) {
32
35
  console.warn("Missing `NUXT_PUBLIC_SUPABASE_URL` in environment or `url` in module options");
33
36
  }
34
- if (!process.env.NUXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY && !options.publishableKey) {
37
+ if (!process.env.NUXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY && !options.publishableKey && !publicSupabaseConfig?.publishableKey) {
35
38
  console.warn(
36
39
  "Missing `NUXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` in environment or `publishableKey` in module options"
37
40
  );
38
41
  }
39
- nuxt.options.runtimeConfig.public.supabase = {
40
- url: options.url,
41
- publishableKey: options.publishableKey,
42
- redirect: options.redirect,
43
- redirectOptions: options.redirectOptions,
44
- clientOptions: options.clientOptions
45
- };
46
- nuxt.options.runtimeConfig.supabase = {
47
- serviceRoleKey: options.secretKey
48
- };
42
+ nuxt.options.runtimeConfig.public.supabase = defu(publicSupabaseConfig, {
43
+ url: options.url ?? "",
44
+ publishableKey: options.publishableKey ?? "",
45
+ redirect: options.redirect ?? false,
46
+ redirectOptions: options.redirectOptions ?? {
47
+ login: "/login",
48
+ exclude: []
49
+ },
50
+ clientOptions: options.clientOptions ?? {
51
+ auth: {
52
+ flowType: "pkce",
53
+ detectSessionInUrl: true,
54
+ persistSession: true,
55
+ autoRefreshToken: true
56
+ }
57
+ }
58
+ });
59
+ nuxt.options.runtimeConfig.supabase = defu(supabaseConfig, {
60
+ serviceRoleKey: options.secretKey ?? ""
61
+ });
49
62
  nuxt.options.alias = {
50
63
  ...nuxt.options.alias,
51
64
  "#supabase/server": resolve("./runtime/server/services")
@@ -62,9 +75,7 @@ const module$1 = defineNuxtModule({
62
75
  });
63
76
  addPlugin(resolve("./runtime/plugins/supabase.server"));
64
77
  addPlugin(resolve("./runtime/plugins/supabase.client"));
65
- nuxt.hook("imports:dirs", (dirs) => {
66
- dirs.push(resolve("./runtime/composables"));
67
- });
78
+ addImportsDir(resolve("./runtime/composables"));
68
79
  if (options.redirect) {
69
80
  addPlugin(resolve("./runtime/plugins/middleware-auth-redirect"));
70
81
  }
@@ -4,7 +4,7 @@ import { useRuntimeConfig } from "#imports";
4
4
  export const supabaseServerClient = async (event) => {
5
5
  const {
6
6
  supabase: { url, publishableKey, clientOptions }
7
- } = useRuntimeConfig().public;
7
+ } = useRuntimeConfig(event).public;
8
8
  let supabaseClient = event.context._supabaseClient;
9
9
  const createTypedServerClient = createServerClient;
10
10
  if (!supabaseClient) {
@@ -7,7 +7,7 @@ export const supabaseServiceRole = async (event) => {
7
7
  public: {
8
8
  supabase: { url, clientOptions }
9
9
  }
10
- } = useRuntimeConfig();
10
+ } = useRuntimeConfig(event);
11
11
  if (!serviceRoleKey) {
12
12
  throw new Error("Missing `SUPABASE_SERVICE_ROLE_KEY` in `.env`");
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floatingpixels/supabase-nuxt",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Supabase module for Nuxt",
5
5
  "repository": "floatingpixels/supabase-nuxt",
6
6
  "license": "MIT",
@@ -59,7 +59,8 @@
59
59
  "dependencies": {
60
60
  "@supabase/ssr": "^0.10.3",
61
61
  "@supabase/supabase-js": "^2.106.2",
62
- "cookie": "^1.1.1"
62
+ "cookie": "^1.1.1",
63
+ "defu": "^6.1.7"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@nuxt/devtools": "4.0.0-alpha.6",
@@ -89,15 +90,5 @@
89
90
  "typescript": "6.0.3",
90
91
  "vitest": "^4.1.7",
91
92
  "vue-tsc": "^3.3.3"
92
- },
93
- "pnpm": {
94
- "onlyBuiltDependencies": [
95
- "@parcel/watcher",
96
- "@prisma/engines",
97
- "@snaplet/seed",
98
- "esbuild",
99
- "supabase",
100
- "unrs-resolver"
101
- ]
102
93
  }
103
94
  }