@floatingpixels/supabase-nuxt 0.2.9 → 0.3.0
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 +10 -8
- package/dist/module.d.mts +4 -4
- package/dist/module.d.ts +4 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +8 -8
- package/dist/runtime/composables/useSupabaseClient.js +1 -1
- package/dist/runtime/plugins/middleware-auth-redirect.d.ts +1 -1
- package/dist/runtime/plugins/middleware-auth-redirect.js +1 -1
- package/dist/runtime/plugins/supabase.client.js +2 -2
- package/dist/runtime/plugins/supabase.server.js +2 -2
- package/dist/runtime/server/services/supabaseServerClient.js +3 -3
- package/dist/runtime/server/services/supabaseServiceRole.js +4 -4
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -31,14 +31,16 @@ export default defineNuxtConfig({
|
|
|
31
31
|
})
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Add `SUPABASE_URL` and `
|
|
34
|
+
Add `SUPABASE_URL` and `SUPABASE_ANON_KEY` to `.env`:
|
|
35
35
|
|
|
36
36
|
```zsh
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
NUXT_PUBLIC_SUPABASE_URL="https://example.supabase.co"
|
|
38
|
+
NUXT_PUBLIC_SUPABASE_ANON_KEY=""
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
When dynamically setting the variables during in an environment, make sure to prefix the environment variables with `NUXT_PUBLIC_` in order to use `runtimeConfig`.
|
|
42
|
+
|
|
43
|
+
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.
|
|
42
44
|
|
|
43
45
|
## Options
|
|
44
46
|
|
|
@@ -55,19 +57,19 @@ export default defineNuxtConfig({
|
|
|
55
57
|
|
|
56
58
|
### `url`
|
|
57
59
|
|
|
58
|
-
Default: `process.env.
|
|
60
|
+
Default: `process.env.NUXT_PUBLIC_SUPABASE_URL` (e.g.: `https://example.supabase.co`)
|
|
59
61
|
|
|
60
62
|
The unique Supabase URL which is supplied when you create a new project in your project dashboard.
|
|
61
63
|
|
|
62
64
|
### `key`
|
|
63
65
|
|
|
64
|
-
Default: `process.env.
|
|
66
|
+
Default: `process.env.NUXT_PUBLIC_SUPABASE_ANON_KEY`
|
|
65
67
|
|
|
66
68
|
Supabase 'anon key', used to bypass the Supabase API gateway and interact with your Supabase database making use of user JWT to apply RLS Policies.
|
|
67
69
|
|
|
68
70
|
### `serviceKey`
|
|
69
71
|
|
|
70
|
-
Default: `process.env.
|
|
72
|
+
Default: `process.env.NUXT_SUPABASE_SERVICE_ROLE_KEY`
|
|
71
73
|
|
|
72
74
|
Supabase 'service role key', has super admin rights and can bypass your Row Level Security.
|
|
73
75
|
|
|
@@ -387,7 +389,7 @@ Make requests with super admin rights to the Supabase API with the `supabaseServ
|
|
|
387
389
|
|
|
388
390
|
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).
|
|
389
391
|
|
|
390
|
-
The client is initialized with the `
|
|
392
|
+
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).
|
|
391
393
|
|
|
392
394
|
> ⚠️ 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.
|
|
393
395
|
|
package/dist/module.d.mts
CHANGED
|
@@ -5,8 +5,8 @@ declare module '@nuxt/schema' {
|
|
|
5
5
|
interface PublicRuntimeConfig {
|
|
6
6
|
supabase: {
|
|
7
7
|
url: string;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
anonKey: string;
|
|
9
|
+
serviceRoleKey: string;
|
|
10
10
|
redirect: boolean;
|
|
11
11
|
redirectOptions: RedirectOptions;
|
|
12
12
|
clientOptions: SupabaseClientOptions<string>;
|
|
@@ -43,7 +43,7 @@ interface ModuleOptions {
|
|
|
43
43
|
* @type string
|
|
44
44
|
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
anonKey: string;
|
|
47
47
|
/**
|
|
48
48
|
* Supabase Service key
|
|
49
49
|
* @default process.env.SUPABASE_SERVICE_KEY
|
|
@@ -51,7 +51,7 @@ interface ModuleOptions {
|
|
|
51
51
|
* @type string
|
|
52
52
|
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
serviceRoleKey?: string;
|
|
55
55
|
/**
|
|
56
56
|
* Redirect automatically to login page if user is not authenticated
|
|
57
57
|
* @default `false`
|
package/dist/module.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ declare module '@nuxt/schema' {
|
|
|
5
5
|
interface PublicRuntimeConfig {
|
|
6
6
|
supabase: {
|
|
7
7
|
url: string;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
anonKey: string;
|
|
9
|
+
serviceRoleKey: string;
|
|
10
10
|
redirect: boolean;
|
|
11
11
|
redirectOptions: RedirectOptions;
|
|
12
12
|
clientOptions: SupabaseClientOptions<string>;
|
|
@@ -43,7 +43,7 @@ interface ModuleOptions {
|
|
|
43
43
|
* @type string
|
|
44
44
|
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
anonKey: string;
|
|
47
47
|
/**
|
|
48
48
|
* Supabase Service key
|
|
49
49
|
* @default process.env.SUPABASE_SERVICE_KEY
|
|
@@ -51,7 +51,7 @@ interface ModuleOptions {
|
|
|
51
51
|
* @type string
|
|
52
52
|
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
serviceRoleKey?: string;
|
|
55
55
|
/**
|
|
56
56
|
* Redirect automatically to login page if user is not authenticated
|
|
57
57
|
* @default `false`
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -11,9 +11,9 @@ const module = defineNuxtModule({
|
|
|
11
11
|
},
|
|
12
12
|
// Default configuration options of the Nuxt module
|
|
13
13
|
defaults: {
|
|
14
|
-
url: process.env.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
url: process.env.NUXT_PUBLIC_SUPABASE_URL,
|
|
15
|
+
anonKey: process.env.NUXT_PUBLIC_SUPABASE_ANON_KEY,
|
|
16
|
+
serviceRoleKey: process.env.NUXT_SUPABASE_SERVICE_ROLE,
|
|
17
17
|
redirect: false,
|
|
18
18
|
redirectOptions: {
|
|
19
19
|
login: "/login",
|
|
@@ -31,20 +31,20 @@ const module = defineNuxtModule({
|
|
|
31
31
|
setup(options, nuxt) {
|
|
32
32
|
const { resolve } = createResolver(import.meta.url);
|
|
33
33
|
if (!options.url) {
|
|
34
|
-
console.warn("Missing `SUPABASE_URL` in
|
|
34
|
+
console.warn("Missing `SUPABASE_URL` in environment");
|
|
35
35
|
}
|
|
36
|
-
if (!options.
|
|
37
|
-
console.warn("Missing `
|
|
36
|
+
if (!options.anonKey) {
|
|
37
|
+
console.warn("Missing `SUPABASE_ANON_KEY` in environment");
|
|
38
38
|
}
|
|
39
39
|
nuxt.options.runtimeConfig.public.supabase = defu(nuxt.options.runtimeConfig.public.supabase, {
|
|
40
40
|
url: options.url,
|
|
41
|
-
|
|
41
|
+
anonKey: options.anonKey,
|
|
42
42
|
redirect: options.redirect,
|
|
43
43
|
redirectOptions: options.redirectOptions,
|
|
44
44
|
clientOptions: options.clientOptions
|
|
45
45
|
});
|
|
46
46
|
nuxt.options.runtimeConfig.supabase = defu(nuxt.options.runtimeConfig.supabase, {
|
|
47
|
-
|
|
47
|
+
serviceRoleKey: options.serviceRoleKey
|
|
48
48
|
});
|
|
49
49
|
addServerHandler({
|
|
50
50
|
route: "/supabase/auth/confirm",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSupabaseUser } from "../composables/useSupabaseUser.js";
|
|
2
|
-
import { defineNuxtPlugin, addRouteMiddleware, defineNuxtRouteMiddleware, useRuntimeConfig, navigateTo } from "
|
|
2
|
+
import { defineNuxtPlugin, addRouteMiddleware, defineNuxtRouteMiddleware, useRuntimeConfig, navigateTo } from "nuxt/app";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "middleware-auth-redirect",
|
|
5
5
|
setup() {
|
|
@@ -5,8 +5,8 @@ export default defineNuxtPlugin({
|
|
|
5
5
|
enforce: "pre",
|
|
6
6
|
async setup() {
|
|
7
7
|
const config = useRuntimeConfig().public.supabase;
|
|
8
|
-
const { url,
|
|
9
|
-
const supabaseBrowserClient = createBrowserClient(url,
|
|
8
|
+
const { url, anonKey } = config;
|
|
9
|
+
const supabaseBrowserClient = createBrowserClient(url, anonKey);
|
|
10
10
|
return {
|
|
11
11
|
provide: {
|
|
12
12
|
supabase: {
|
|
@@ -5,12 +5,12 @@ export default defineNuxtPlugin({
|
|
|
5
5
|
name: "supabase",
|
|
6
6
|
enforce: "pre",
|
|
7
7
|
async setup() {
|
|
8
|
-
const { url,
|
|
8
|
+
const { url, anonKey } = useRuntimeConfig().public.supabase;
|
|
9
9
|
const event = useRequestEvent();
|
|
10
10
|
if (!event) {
|
|
11
11
|
throw new Error("No request event found");
|
|
12
12
|
}
|
|
13
|
-
const supabaseServerClient = createServerClient(url,
|
|
13
|
+
const supabaseServerClient = createServerClient(url, anonKey, {
|
|
14
14
|
cookies: {
|
|
15
15
|
getAll: async () => {
|
|
16
16
|
return parseCookieHeader(getHeader(event, "Cookie") ?? "");
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createServerClient, parseCookieHeader } from "@supabase/ssr";
|
|
2
2
|
import { setCookie, getHeader } from "h3";
|
|
3
|
-
import { useRuntimeConfig } from "
|
|
3
|
+
import { useRuntimeConfig } from "nuxt/app";
|
|
4
4
|
export const supabaseServerClient = async (event) => {
|
|
5
5
|
const {
|
|
6
|
-
supabase: { url,
|
|
6
|
+
supabase: { url, anonKey }
|
|
7
7
|
} = useRuntimeConfig().public;
|
|
8
8
|
let supabaseClient = event.context._supabaseClient;
|
|
9
9
|
if (!supabaseClient) {
|
|
10
|
-
supabaseClient = createServerClient(url,
|
|
10
|
+
supabaseClient = createServerClient(url, anonKey, {
|
|
11
11
|
cookies: {
|
|
12
12
|
getAll: async () => {
|
|
13
13
|
return parseCookieHeader(getHeader(event, "Cookie") ?? "");
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createServerClient, parseCookieHeader } from "@supabase/ssr";
|
|
2
2
|
import { setCookie, getHeader } from "h3";
|
|
3
|
-
import { useRuntimeConfig } from "
|
|
3
|
+
import { useRuntimeConfig } from "nuxt/app";
|
|
4
4
|
export const supabaseServiceRole = async (event) => {
|
|
5
5
|
const {
|
|
6
|
-
supabase: {
|
|
6
|
+
supabase: { serviceRoleKey },
|
|
7
7
|
public: {
|
|
8
8
|
supabase: { url }
|
|
9
9
|
}
|
|
10
10
|
} = useRuntimeConfig();
|
|
11
|
-
if (!
|
|
11
|
+
if (!serviceRoleKey) {
|
|
12
12
|
throw new Error("Missing `SUPABASE_SERVICE_KEY` in `.env`");
|
|
13
13
|
}
|
|
14
14
|
let supabaseClient = event.context._supabaseServiceRole;
|
|
15
15
|
if (!supabaseClient) {
|
|
16
|
-
supabaseClient = createServerClient(url,
|
|
16
|
+
supabaseClient = createServerClient(url, serviceRoleKey, {
|
|
17
17
|
cookies: {
|
|
18
18
|
getAll: async () => {
|
|
19
19
|
return parseCookieHeader(getHeader(event, "Cookie") ?? "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floatingpixels/supabase-nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Supabase module for Nuxt",
|
|
5
5
|
"repository": "floatingpixels/supabase-nuxt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,36 +58,36 @@
|
|
|
58
58
|
"db:fullseed": "(npx @snaplet/seed sync) -and (npx tsx seed.ts)"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@nuxt/kit": "^3.14.1592",
|
|
62
61
|
"@supabase/ssr": "^0.5.2",
|
|
63
|
-
"@supabase/supabase-js": "^2.47.
|
|
62
|
+
"@supabase/supabase-js": "^2.47.12",
|
|
64
63
|
"defu": "^6.1.4"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
|
-
"@nuxt/devtools": "^1.
|
|
68
|
-
"@nuxt/eslint-config": "^0.7.
|
|
66
|
+
"@nuxt/devtools": "^1.7.0",
|
|
67
|
+
"@nuxt/eslint-config": "^0.7.5",
|
|
68
|
+
"@nuxt/kit": "^3.15.1",
|
|
69
69
|
"@nuxt/module-builder": "^0.8.4",
|
|
70
|
-
"@nuxt/schema": "^3.
|
|
71
|
-
"@nuxt/test-utils": "
|
|
70
|
+
"@nuxt/schema": "^3.15.1",
|
|
71
|
+
"@nuxt/test-utils": "3.15.1",
|
|
72
72
|
"@playwright/test": "^1.49.1",
|
|
73
|
-
"@snaplet/copycat": "^5.1.
|
|
73
|
+
"@snaplet/copycat": "^5.1.1",
|
|
74
74
|
"@snaplet/seed": "^0.98.0",
|
|
75
75
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
76
|
-
"@types/node": "^22.10.
|
|
76
|
+
"@types/node": "^22.10.5",
|
|
77
77
|
"@vitest/coverage-v8": "2.1.8",
|
|
78
78
|
"@vue/test-utils": "^2.4.6",
|
|
79
79
|
"changelogen": "^0.5.7",
|
|
80
80
|
"eslint": "^9.17.0",
|
|
81
81
|
"eslint-config-prettier": "^9.1.0",
|
|
82
|
-
"happy-dom": "^
|
|
83
|
-
"nuxt": "^3.
|
|
82
|
+
"happy-dom": "^16.5.3",
|
|
83
|
+
"nuxt": "^3.15.1",
|
|
84
84
|
"playwright-core": "^1.49.1",
|
|
85
85
|
"postgres": "^3.4.5",
|
|
86
86
|
"prettier": "^3.4.2",
|
|
87
|
-
"release-it": "^
|
|
88
|
-
"supabase": "^2.
|
|
89
|
-
"typescript": "5.
|
|
87
|
+
"release-it": "^18.1.1",
|
|
88
|
+
"supabase": "^2.2.1",
|
|
89
|
+
"typescript": "5.7.3",
|
|
90
90
|
"vitest": "^2.1.8",
|
|
91
|
-
"vue-tsc": "^2.
|
|
91
|
+
"vue-tsc": "^2.2.0"
|
|
92
92
|
}
|
|
93
93
|
}
|