@floatingpixels/supabase-nuxt 0.1.9 → 0.2.1
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 +15 -12
- package/dist/module.d.mts +77 -98
- package/dist/module.d.ts +77 -98
- package/dist/module.json +5 -1
- package/dist/module.mjs +3 -3
- package/dist/runtime/composables/useSupabaseClient.d.ts +2 -2
- package/dist/runtime/composables/useSupabaseUser.js +6 -0
- package/dist/runtime/plugins/middleware-auth-redirect.d.ts +1 -1
- package/dist/runtime/plugins/{middleware-auth-redirect.mjs → middleware-auth-redirect.js} +4 -5
- package/dist/runtime/plugins/{supabase.client.mjs → supabase.client.js} +1 -12
- package/dist/runtime/plugins/{supabase.server.mjs → supabase.server.js} +8 -8
- package/dist/runtime/server/auth/{confirm.mjs → confirm.js} +0 -1
- package/dist/runtime/server/services/index.d.ts +2 -2
- package/dist/runtime/server/services/index.js +2 -0
- package/dist/runtime/server/services/supabaseServerClient.d.ts +3 -3
- package/dist/runtime/server/services/{supabaseServerClient.mjs → supabaseServerClient.js} +8 -8
- package/dist/runtime/server/services/supabaseServiceRole.d.ts +3 -3
- package/dist/runtime/server/services/{supabaseServiceRole.mjs → supabaseServiceRole.js} +8 -8
- package/dist/types.d.mts +4 -5
- package/dist/types.d.ts +4 -5
- package/package.json +26 -21
- package/dist/runtime/composables/useSupabaseUser.mjs +0 -11
- package/dist/runtime/server/services/index.mjs +0 -2
- package/dist/runtime/types/index.d.ts +0 -102
- /package/dist/runtime/composables/{useSupabaseClient.mjs → useSupabaseClient.js} +0 -0
- /package/dist/runtime/server/auth/{callback.mjs → callback.js} +0 -0
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ SUPABASE_URL="https://example.supabase.co"
|
|
|
38
38
|
SUPABASE_KEY="<your_key>"
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Alternatively, you can prefix the
|
|
41
|
+
Alternatively, you can prefix the environment variables with `NUXT_PUBLIC_` in order to use `runtimeConfig`.
|
|
42
42
|
|
|
43
43
|
## Options
|
|
44
44
|
|
|
45
|
-
You can configure the
|
|
45
|
+
You can configure the Supabase module by using the `supabase` key in `nuxt.config`:
|
|
46
46
|
|
|
47
47
|
```ts [nuxt.config.ts]
|
|
48
48
|
export default defineNuxtConfig({
|
|
@@ -75,7 +75,7 @@ Supabase 'service role key', has super admin rights and can bypass your Row Leve
|
|
|
75
75
|
|
|
76
76
|
Default: `false`
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
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.
|
|
79
79
|
|
|
80
80
|
### `redirectOptions`
|
|
81
81
|
|
|
@@ -89,7 +89,7 @@ Default:
|
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
- `login`: User will be redirected to this route if not authenticated or after logout.
|
|
92
|
-
- `exclude`: Routes to exclude from the
|
|
92
|
+
- `exclude`: Routes to exclude from the re-direct. `['/foo', '/bar/*']` will exclude the `foo` page and all pages in your `bar` folder.
|
|
93
93
|
|
|
94
94
|
### cookieOptions
|
|
95
95
|
|
|
@@ -154,7 +154,7 @@ const signInWithOtp = async () => {
|
|
|
154
154
|
|
|
155
155
|
> ⚠️ Ensure to activate and configure the authentication providers you want to use in the Supabase Dashboard under `Authentication -> Providers`.
|
|
156
156
|
|
|
157
|
-
Once the authorization flow is triggered using the `auth` wrapper of the `useSupabaseClient` composable, the session management is handled automatically. For the authentication flow PKCE is used, which requires an exchange between your server and the Supabase authentication server for some authentication methods.
|
|
157
|
+
Once the authorization flow is triggered using the `auth` wrapper of the `useSupabaseClient` composable, the session management is handled automatically. For the authentication flow PKCE is used, which requires an exchange between your server and the Supabase authentication server for some authentication methods.
|
|
158
158
|
|
|
159
159
|
### E-Mail Authentication
|
|
160
160
|
|
|
@@ -171,9 +171,9 @@ When using e-mail authentication, a confirmation e-mail is sent to new users, an
|
|
|
171
171
|
</p>
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
The confirmation route on your server is provided by this module, so you don't need to implement it yourself. It's available at `/supabase/auth/confirm`. It will automatically confirm the user and
|
|
174
|
+
The confirmation route on your server is provided by this module, so you don't need to implement it yourself. It's available at `/supabase/auth/confirm`. It will automatically confirm the user and re-direct to the `next` route.
|
|
175
175
|
|
|
176
|
-
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 `next` URL parameter if provided. You can use the `useSupabaseClient` composable to confirm the user and
|
|
176
|
+
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 `next` URL parameter if provided. You can use the `useSupabaseClient` composable to confirm the user and re-direct to the `next` route:
|
|
177
177
|
|
|
178
178
|
> ⚠️ You can use the provided confirm route at `/supabase/confirm`, the implementation of a custom route is optional!
|
|
179
179
|
|
|
@@ -247,7 +247,7 @@ export default defineEventHandler(async event => {
|
|
|
247
247
|
|
|
248
248
|
### Redirection for non-authorized users
|
|
249
249
|
|
|
250
|
-
If `redirect` is set to `true` in the module options, users will be automatically routed to the login page when they are not authenticated. If you want to allow access to "public" pages, you just need to add them in the `exclude` `redirect` option, and they will not
|
|
250
|
+
If `redirect` is set to `true` in the module options, users will be automatically routed to the login page when they are not authenticated. If you want to allow access to "public" pages, you just need to add them in the `exclude` `redirect` option, and they will not re-direct unauthenticated users.
|
|
251
251
|
|
|
252
252
|
### Error Handling
|
|
253
253
|
|
|
@@ -276,7 +276,7 @@ const handleError = () => clearError({ redirect: '/' })
|
|
|
276
276
|
|
|
277
277
|
### useSupabaseClient
|
|
278
278
|
|
|
279
|
-
This composable can be used to make requests to the Supabase API. It's
|
|
279
|
+
This composable can be used to make requests to the Supabase API. It's auto-imported and ready to use in your components. It's using [supabase-js](https://github.com/supabase/supabase-js/) under the hood, it gives access to the [Supabase client](https://supabase.com/docs/reference/javascript/initializing) and all of its features.
|
|
280
280
|
|
|
281
281
|
#### Database Request
|
|
282
282
|
|
|
@@ -302,7 +302,7 @@ Based on [Supabase Realtime](https://github.com/supabase/realtime), listen to ch
|
|
|
302
302
|
|
|
303
303
|
To enable it, make sure you have turned on the [Realtime API](https://supabase.com/docs/guides/api#realtime-api) for your table.
|
|
304
304
|
|
|
305
|
-
Then, listen to changes directly in your
|
|
305
|
+
Then, listen to changes directly in your Vue page / component:
|
|
306
306
|
|
|
307
307
|
```vue
|
|
308
308
|
<script setup lang="ts">
|
|
@@ -348,7 +348,7 @@ const client = useSupabaseClient<Database>()
|
|
|
348
348
|
|
|
349
349
|
#### Authentication Client
|
|
350
350
|
|
|
351
|
-
The useSupabaseClient composable is providing all methods to manage authorization under `useSupabaseClient().auth`. For more details please see the [supabase-js auth documentation](https://supabase.com/docs/reference/javascript/auth-api). Here is an example for signing in and out:
|
|
351
|
+
The `useSupabaseClient` composable is providing all methods to manage authorization under `useSupabaseClient().auth`. For more details please see the [supabase-js auth documentation](https://supabase.com/docs/reference/javascript/auth-api). Here is an example for signing in and out:
|
|
352
352
|
|
|
353
353
|
> ⚠️ If you want a full explanation on how to handle the authentication process, please read this [section](#authentication).
|
|
354
354
|
|
|
@@ -395,7 +395,7 @@ export default eventHandler(async event => {
|
|
|
395
395
|
|
|
396
396
|
### supabaseServiceRole
|
|
397
397
|
|
|
398
|
-
Make requests with super admin rights to the Supabase API with the `supabaseServiceRole` service. This function is designed to work only in [server routes](https://nuxt.com/docs/guide/directory-structure/server#server-routes), there is no
|
|
398
|
+
Make requests with super admin rights to the Supabase API with the `supabaseServiceRole` service. This function is designed to work only in [server routes](https://nuxt.com/docs/guide/directory-structure/server#server-routes), there is no Vue composable equivalent.
|
|
399
399
|
|
|
400
400
|
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).
|
|
401
401
|
|
|
@@ -416,3 +416,6 @@ export default eventHandler(async event => {
|
|
|
416
416
|
return { sensitiveData: data }
|
|
417
417
|
})
|
|
418
418
|
```
|
|
419
|
+
|
|
420
|
+
<!-- markdownlint-disable-file MD013 -->
|
|
421
|
+
<!-- markdownlint-disable-file MD033 -->
|
package/dist/module.d.mts
CHANGED
|
@@ -2,107 +2,86 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
import { SupabaseClientOptions } from '@supabase/supabase-js';
|
|
3
3
|
import { CookieOptions } from 'nuxt/app';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
interface RedirectOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Login route
|
|
8
|
+
* @default '/login'
|
|
9
|
+
* @type string
|
|
10
|
+
*/
|
|
11
|
+
login?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Routes to exclude from redirection
|
|
14
|
+
* @default []
|
|
15
|
+
* @type string[]
|
|
16
|
+
*/
|
|
17
|
+
exclude?: string[];
|
|
17
18
|
}
|
|
18
19
|
interface ModuleOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
}
|
|
85
|
-
* @type object
|
|
86
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
87
|
-
*/
|
|
88
|
-
clientOptions?: SupabaseClientOptions<string>
|
|
20
|
+
/**
|
|
21
|
+
* Supabase API URL
|
|
22
|
+
* @default process.env.SUPABASE_URL
|
|
23
|
+
* @example 'https://*.supabase.co'
|
|
24
|
+
* @type string
|
|
25
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
26
|
+
*/
|
|
27
|
+
url: string;
|
|
28
|
+
/**
|
|
29
|
+
* Supabase Client API Key
|
|
30
|
+
* @default process.env.SUPABASE_KEY
|
|
31
|
+
* @example '123456789'
|
|
32
|
+
* @type string
|
|
33
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
34
|
+
*/
|
|
35
|
+
key: string;
|
|
36
|
+
/**
|
|
37
|
+
* Supabase Service key
|
|
38
|
+
* @default process.env.SUPABASE_SERVICE_KEY
|
|
39
|
+
* @example '123456789'
|
|
40
|
+
* @type string
|
|
41
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
42
|
+
*/
|
|
43
|
+
serviceKey?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Redirect automatically to login page if user is not authenticated
|
|
46
|
+
* @default `false`
|
|
47
|
+
* @type boolean
|
|
48
|
+
*/
|
|
49
|
+
redirect?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Redirection options, set routes for login and specify pages to exclude from redirection
|
|
52
|
+
* @default
|
|
53
|
+
* {
|
|
54
|
+
login: '/login',
|
|
55
|
+
exclude: [],
|
|
56
|
+
}
|
|
57
|
+
* @type RedirectOptions
|
|
58
|
+
*/
|
|
59
|
+
redirectOptions?: RedirectOptions;
|
|
60
|
+
/**
|
|
61
|
+
* Cookie options
|
|
62
|
+
* @default {
|
|
63
|
+
maxAge: 60 * 60 * 8,
|
|
64
|
+
sameSite: 'lax',
|
|
65
|
+
secure: true,
|
|
66
|
+
}
|
|
67
|
+
* @type CookieOptions
|
|
68
|
+
* @docs https://nuxt.com/docs/api/composables/use-cookie#options
|
|
69
|
+
*/
|
|
70
|
+
cookieOptions?: CookieOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Supabase Client options
|
|
73
|
+
* @default {
|
|
74
|
+
auth: {
|
|
75
|
+
flowType: 'pkce',
|
|
76
|
+
detectSessionInUrl: true,
|
|
77
|
+
persistSession: true,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
* @type object
|
|
81
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
82
|
+
*/
|
|
83
|
+
clientOptions?: SupabaseClientOptions<string>;
|
|
89
84
|
}
|
|
90
|
-
|
|
91
|
-
interface RedirectOptions {
|
|
92
|
-
/**
|
|
93
|
-
* Login route
|
|
94
|
-
* @default '/login'
|
|
95
|
-
* @type string
|
|
96
|
-
*/
|
|
97
|
-
login?: string
|
|
98
|
-
/**
|
|
99
|
-
* Routes to exclude from redirection
|
|
100
|
-
* @default []
|
|
101
|
-
* @type string[]
|
|
102
|
-
*/
|
|
103
|
-
exclude?: string[]
|
|
104
|
-
}
|
|
105
|
-
|
|
106
85
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
107
86
|
|
|
108
87
|
export { _default as default };
|
package/dist/module.d.ts
CHANGED
|
@@ -2,107 +2,86 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
import { SupabaseClientOptions } from '@supabase/supabase-js';
|
|
3
3
|
import { CookieOptions } from 'nuxt/app';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
interface RedirectOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Login route
|
|
8
|
+
* @default '/login'
|
|
9
|
+
* @type string
|
|
10
|
+
*/
|
|
11
|
+
login?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Routes to exclude from redirection
|
|
14
|
+
* @default []
|
|
15
|
+
* @type string[]
|
|
16
|
+
*/
|
|
17
|
+
exclude?: string[];
|
|
17
18
|
}
|
|
18
19
|
interface ModuleOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
}
|
|
85
|
-
* @type object
|
|
86
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
87
|
-
*/
|
|
88
|
-
clientOptions?: SupabaseClientOptions<string>
|
|
20
|
+
/**
|
|
21
|
+
* Supabase API URL
|
|
22
|
+
* @default process.env.SUPABASE_URL
|
|
23
|
+
* @example 'https://*.supabase.co'
|
|
24
|
+
* @type string
|
|
25
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
26
|
+
*/
|
|
27
|
+
url: string;
|
|
28
|
+
/**
|
|
29
|
+
* Supabase Client API Key
|
|
30
|
+
* @default process.env.SUPABASE_KEY
|
|
31
|
+
* @example '123456789'
|
|
32
|
+
* @type string
|
|
33
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
34
|
+
*/
|
|
35
|
+
key: string;
|
|
36
|
+
/**
|
|
37
|
+
* Supabase Service key
|
|
38
|
+
* @default process.env.SUPABASE_SERVICE_KEY
|
|
39
|
+
* @example '123456789'
|
|
40
|
+
* @type string
|
|
41
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
42
|
+
*/
|
|
43
|
+
serviceKey?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Redirect automatically to login page if user is not authenticated
|
|
46
|
+
* @default `false`
|
|
47
|
+
* @type boolean
|
|
48
|
+
*/
|
|
49
|
+
redirect?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Redirection options, set routes for login and specify pages to exclude from redirection
|
|
52
|
+
* @default
|
|
53
|
+
* {
|
|
54
|
+
login: '/login',
|
|
55
|
+
exclude: [],
|
|
56
|
+
}
|
|
57
|
+
* @type RedirectOptions
|
|
58
|
+
*/
|
|
59
|
+
redirectOptions?: RedirectOptions;
|
|
60
|
+
/**
|
|
61
|
+
* Cookie options
|
|
62
|
+
* @default {
|
|
63
|
+
maxAge: 60 * 60 * 8,
|
|
64
|
+
sameSite: 'lax',
|
|
65
|
+
secure: true,
|
|
66
|
+
}
|
|
67
|
+
* @type CookieOptions
|
|
68
|
+
* @docs https://nuxt.com/docs/api/composables/use-cookie#options
|
|
69
|
+
*/
|
|
70
|
+
cookieOptions?: CookieOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Supabase Client options
|
|
73
|
+
* @default {
|
|
74
|
+
auth: {
|
|
75
|
+
flowType: 'pkce',
|
|
76
|
+
detectSessionInUrl: true,
|
|
77
|
+
persistSession: true,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
* @type object
|
|
81
|
+
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
82
|
+
*/
|
|
83
|
+
clientOptions?: SupabaseClientOptions<string>;
|
|
89
84
|
}
|
|
90
|
-
|
|
91
|
-
interface RedirectOptions {
|
|
92
|
-
/**
|
|
93
|
-
* Login route
|
|
94
|
-
* @default '/login'
|
|
95
|
-
* @type string
|
|
96
|
-
*/
|
|
97
|
-
login?: string
|
|
98
|
-
/**
|
|
99
|
-
* Routes to exclude from redirection
|
|
100
|
-
* @default []
|
|
101
|
-
* @type string[]
|
|
102
|
-
*/
|
|
103
|
-
exclude?: string[]
|
|
104
|
-
}
|
|
105
|
-
|
|
106
85
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
107
86
|
|
|
108
87
|
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerHandler, addPlugin,
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addTypeTemplate, extendViteConfig } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
@@ -46,9 +46,9 @@ const module = defineNuxtModule({
|
|
|
46
46
|
key: options.key,
|
|
47
47
|
redirect: options.redirect,
|
|
48
48
|
redirectOptions: options.redirectOptions,
|
|
49
|
-
cookieOptions: options.cookieOptions,
|
|
50
49
|
clientOptions: options.clientOptions
|
|
51
50
|
});
|
|
51
|
+
nuxt.options.runtimeConfig.public.supabase.cookieOptions = nuxt.options.runtimeConfig.public.supabase.cookieOptions || options.cookieOptions;
|
|
52
52
|
nuxt.options.runtimeConfig.supabase = defu(nuxt.options.runtimeConfig.supabase, {
|
|
53
53
|
serviceKey: options.serviceKey
|
|
54
54
|
});
|
|
@@ -77,7 +77,7 @@ const module = defineNuxtModule({
|
|
|
77
77
|
inline: [resolve("./runtime")]
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
addTypeTemplate({
|
|
81
81
|
filename: "types/supabase.d.ts",
|
|
82
82
|
getContents: () => [
|
|
83
83
|
"declare module '#supabase/server' {",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
export declare const useSupabaseClient: <T>() => SupabaseClient<T
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
export declare const useSupabaseClient: <T>() => SupabaseClient<T>;
|
|
@@ -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,10 +1,10 @@
|
|
|
1
|
-
import { useSupabaseUser } from "../composables/useSupabaseUser.
|
|
1
|
+
import { useSupabaseUser } from "../composables/useSupabaseUser.js";
|
|
2
2
|
import { defineNuxtPlugin, addRouteMiddleware, defineNuxtRouteMiddleware, useRuntimeConfig, navigateTo } from "#imports";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "middleware-auth-redirect",
|
|
5
5
|
setup() {
|
|
6
6
|
addRouteMiddleware(
|
|
7
|
-
"
|
|
7
|
+
"01-global-auth-redirect",
|
|
8
8
|
defineNuxtRouteMiddleware(async (to) => {
|
|
9
9
|
const config = useRuntimeConfig().public.supabase;
|
|
10
10
|
const { login, exclude } = config.redirectOptions;
|
|
@@ -12,11 +12,10 @@ export default defineNuxtPlugin({
|
|
|
12
12
|
const regex = new RegExp(`^${path.replace(/\*/g, ".*")}$`);
|
|
13
13
|
return regex.test(to.path);
|
|
14
14
|
});
|
|
15
|
-
if (isExcluded)
|
|
16
|
-
return;
|
|
15
|
+
if (isExcluded) return;
|
|
17
16
|
const user = await useSupabaseUser();
|
|
18
17
|
if (!user) {
|
|
19
|
-
return navigateTo("/login");
|
|
18
|
+
return navigateTo("/login", { redirectCode: 302 });
|
|
20
19
|
}
|
|
21
20
|
}),
|
|
22
21
|
{ global: true }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
|
|
2
2
|
import { createBrowserClient } from "@supabase/ssr";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "supabase",
|
|
@@ -7,17 +7,6 @@ export default defineNuxtPlugin({
|
|
|
7
7
|
const config = useRuntimeConfig().public.supabase;
|
|
8
8
|
const { url, key, cookieOptions } = config;
|
|
9
9
|
const supabaseBrowserClient = createBrowserClient(url, key, {
|
|
10
|
-
cookies: {
|
|
11
|
-
get(name) {
|
|
12
|
-
return useCookie(name).value;
|
|
13
|
-
},
|
|
14
|
-
set(name, value) {
|
|
15
|
-
useCookie(name, { ...cookieOptions, readonly: false }).value = value;
|
|
16
|
-
},
|
|
17
|
-
remove(key2, options) {
|
|
18
|
-
useCookie(key2, { ...options, expires: 0 }).value = "";
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
10
|
cookieOptions,
|
|
22
11
|
isSingleton: true
|
|
23
12
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineNuxtPlugin, useRuntimeConfig, useRequestEvent } from "nuxt/app";
|
|
2
2
|
import { createServerClient } from "@supabase/ssr";
|
|
3
|
-
import {
|
|
3
|
+
import { setCookie, parseCookies } from "h3";
|
|
4
4
|
export default defineNuxtPlugin({
|
|
5
5
|
name: "supabase",
|
|
6
6
|
enforce: "pre",
|
|
@@ -9,14 +9,14 @@ export default defineNuxtPlugin({
|
|
|
9
9
|
const event = useRequestEvent();
|
|
10
10
|
const supabaseServerClient = createServerClient(url, key, {
|
|
11
11
|
cookies: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
getAll: async () => {
|
|
13
|
+
const cookies = parseCookies(event);
|
|
14
|
+
return Object.entries(cookies).map(([name, value]) => ({ name, value }));
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setCookie(event, key2, "", { ...options, expires: 0 });
|
|
16
|
+
setAll: async (cookiesToSet) => {
|
|
17
|
+
cookiesToSet.forEach(({ name, value, options }) => {
|
|
18
|
+
setCookie(event, name, value, { ...cookieOptions, ...options });
|
|
19
|
+
});
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
cookieOptions
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { supabaseServerClient } from './supabaseServerClient';
|
|
2
|
-
export { supabaseServiceRole } from './supabaseServiceRole';
|
|
1
|
+
export { supabaseServerClient } from './supabaseServerClient.js';
|
|
2
|
+
export { supabaseServiceRole } from './supabaseServiceRole.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { H3Event } from 'h3';
|
|
3
|
-
export declare const supabaseServerClient: <T>(event: H3Event) => Promise<SupabaseClient<T
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
import type { H3Event } from 'h3';
|
|
3
|
+
export declare const supabaseServerClient: <T>(event: H3Event) => Promise<SupabaseClient<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createServerClient } from "@supabase/ssr";
|
|
2
|
-
import {
|
|
2
|
+
import { parseCookies, setCookie } from "h3";
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
export const supabaseServerClient = async (event) => {
|
|
5
5
|
const {
|
|
@@ -9,14 +9,14 @@ export const supabaseServerClient = async (event) => {
|
|
|
9
9
|
if (!supabaseClient) {
|
|
10
10
|
supabaseClient = createServerClient(url, key, {
|
|
11
11
|
cookies: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
getAll: async () => {
|
|
13
|
+
const cookies = parseCookies(event);
|
|
14
|
+
return Object.entries(cookies).map(([name, value]) => ({ name, value }));
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setCookie(event, key2, "", { ...options, expires: 0 });
|
|
16
|
+
setAll: async (cookiesToSet) => {
|
|
17
|
+
cookiesToSet.forEach(({ name, value, options }) => {
|
|
18
|
+
setCookie(event, name, value, { ...cookieOptions, ...options });
|
|
19
|
+
});
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
cookieOptions
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { H3Event } from 'h3';
|
|
3
|
-
export declare const supabaseServiceRole: <T>(event: H3Event) => Promise<SupabaseClient<T
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
import type { H3Event } from 'h3';
|
|
3
|
+
export declare const supabaseServiceRole: <T>(event: H3Event) => Promise<SupabaseClient<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createServerClient } from "@supabase/ssr";
|
|
2
|
-
import {
|
|
2
|
+
import { parseCookies, setCookie } from "h3";
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
export const supabaseServiceRole = async (event) => {
|
|
5
5
|
const {
|
|
@@ -15,14 +15,14 @@ export const supabaseServiceRole = async (event) => {
|
|
|
15
15
|
if (!supabaseClient) {
|
|
16
16
|
supabaseClient = createServerClient(url, serviceKey, {
|
|
17
17
|
cookies: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
getAll: async () => {
|
|
19
|
+
const cookies = parseCookies(event);
|
|
20
|
+
return Object.entries(cookies).map(([name, value]) => ({ name, value }));
|
|
20
21
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setCookie(event, key, "", { ...options, expires: 0 });
|
|
22
|
+
setAll: async (cookiesToSet) => {
|
|
23
|
+
cookiesToSet.forEach(({ name, value, options }) => {
|
|
24
|
+
setCookie(event, name, value, { ...cookieOptions, ...options });
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
cookieOptions
|
package/dist/types.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
1
2
|
|
|
2
|
-
import type {
|
|
3
|
+
import type { default as Module } from './module.js'
|
|
3
4
|
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export type { default } from './module.js'
|
|
7
|
+
export { default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
1
2
|
|
|
2
|
-
import type {
|
|
3
|
+
import type { default as Module } from './module'
|
|
3
4
|
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export type { default } from './module'
|
|
7
|
+
export { default } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floatingpixels/supabase-nuxt",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Supabase module for Nuxt",
|
|
5
5
|
"repository": "floatingpixels/supabase-nuxt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,35 +38,40 @@
|
|
|
38
38
|
"dev": "nuxi dev playground",
|
|
39
39
|
"dev:build": "nuxi build playground",
|
|
40
40
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
41
|
-
"release": "
|
|
41
|
+
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
42
42
|
"lint": "eslint .",
|
|
43
43
|
"test": "vitest run",
|
|
44
44
|
"test:watch": "vitest watch"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@nuxt/kit": "^3.
|
|
48
|
-
"@supabase/ssr": "^0.0
|
|
49
|
-
"@supabase/supabase-js": "^2.
|
|
47
|
+
"@nuxt/kit": "^3.12.2",
|
|
48
|
+
"@supabase/ssr": "^0.4.0",
|
|
49
|
+
"@supabase/supabase-js": "^2.44.2",
|
|
50
50
|
"defu": "^6.1.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@nuxt/devtools": "^1.
|
|
54
|
-
"@nuxt/eslint-config": "^0.
|
|
55
|
-
"@nuxt/module-builder": "^0.
|
|
56
|
-
"@nuxt/schema": "^3.
|
|
57
|
-
"@nuxt/test-utils": "^3.
|
|
58
|
-
"@types/node": "^20.
|
|
59
|
-
"@vue/test-utils": "^2.4.
|
|
53
|
+
"@nuxt/devtools": "^1.3.7",
|
|
54
|
+
"@nuxt/eslint-config": "^0.3.13",
|
|
55
|
+
"@nuxt/module-builder": "^0.8.1",
|
|
56
|
+
"@nuxt/schema": "^3.12.2",
|
|
57
|
+
"@nuxt/test-utils": "^3.13.1",
|
|
58
|
+
"@types/node": "^20.14.9",
|
|
59
|
+
"@vue/test-utils": "^2.4.6",
|
|
60
60
|
"changelogen": "^0.5.5",
|
|
61
|
-
"eslint": "^
|
|
61
|
+
"eslint": "^9.6.0",
|
|
62
62
|
"eslint-config-prettier": "^9.1.0",
|
|
63
|
-
"happy-dom": "^
|
|
64
|
-
"nuxt": "^3.
|
|
65
|
-
"playwright-core": "^1.
|
|
66
|
-
"prettier": "^3.2
|
|
67
|
-
"release-it": "^17.
|
|
68
|
-
"typescript": "^5.
|
|
69
|
-
"vitest": "^1.
|
|
70
|
-
"vue-tsc": "^
|
|
63
|
+
"happy-dom": "^14.12.3",
|
|
64
|
+
"nuxt": "^3.12.2",
|
|
65
|
+
"playwright-core": "^1.45.0",
|
|
66
|
+
"prettier": "^3.3.2",
|
|
67
|
+
"release-it": "^17.4.1",
|
|
68
|
+
"typescript": "^5.5.2",
|
|
69
|
+
"vitest": "^1.6.0",
|
|
70
|
+
"vue-tsc": "^2.0.24"
|
|
71
|
+
},
|
|
72
|
+
"pnpm": {
|
|
73
|
+
"overrides": {
|
|
74
|
+
"vite-plugin-checker": "0.7.0"
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useSupabaseClient } from "./useSupabaseClient.mjs";
|
|
2
|
-
export const useSupabaseUser = async () => {
|
|
3
|
-
const supabase = useSupabaseClient();
|
|
4
|
-
const {
|
|
5
|
-
data: { session }
|
|
6
|
-
} = await supabase.auth.getSession();
|
|
7
|
-
if (!session?.user) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
return session.user;
|
|
11
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { SupabaseClientOptions } from '@supabase/supabase-js'
|
|
2
|
-
import { CookieOptions } from 'nuxt/app'
|
|
3
|
-
declare module '@nuxt/schema' {
|
|
4
|
-
interface PublicRuntimeConfig {
|
|
5
|
-
supabase: {
|
|
6
|
-
url: string
|
|
7
|
-
key: string
|
|
8
|
-
redirect: boolean
|
|
9
|
-
redirectOptions: RedirectOptions
|
|
10
|
-
cookieName: string
|
|
11
|
-
cookieOptions: CookieOptions
|
|
12
|
-
clientOptions: SupabaseClientOptions<string>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export interface ModuleOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Supabase API URL
|
|
19
|
-
* @default process.env.SUPABASE_URL
|
|
20
|
-
* @example 'https://*.supabase.co'
|
|
21
|
-
* @type string
|
|
22
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
23
|
-
*/
|
|
24
|
-
url: string
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Supabase Client API Key
|
|
28
|
-
* @default process.env.SUPABASE_KEY
|
|
29
|
-
* @example '123456789'
|
|
30
|
-
* @type string
|
|
31
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
32
|
-
*/
|
|
33
|
-
key: string
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Supabase Service key
|
|
37
|
-
* @default process.env.SUPABASE_SERVICE_KEY
|
|
38
|
-
* @example '123456789'
|
|
39
|
-
* @type string
|
|
40
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
41
|
-
*/
|
|
42
|
-
serviceKey?: string
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Redirect automatically to login page if user is not authenticated
|
|
46
|
-
* @default `false`
|
|
47
|
-
* @type boolean
|
|
48
|
-
*/
|
|
49
|
-
redirect?: boolean
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Redirection options, set routes for login and specify pages to exclude from redirection
|
|
53
|
-
* @default
|
|
54
|
-
* {
|
|
55
|
-
login: '/login',
|
|
56
|
-
exclude: [],
|
|
57
|
-
}
|
|
58
|
-
* @type RedirectOptions
|
|
59
|
-
*/
|
|
60
|
-
redirectOptions?: RedirectOptions
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Cookie options
|
|
64
|
-
* @default {
|
|
65
|
-
maxAge: 60 * 60 * 8,
|
|
66
|
-
sameSite: 'lax',
|
|
67
|
-
secure: true,
|
|
68
|
-
}
|
|
69
|
-
* @type CookieOptions
|
|
70
|
-
* @docs https://nuxt.com/docs/api/composables/use-cookie#options
|
|
71
|
-
*/
|
|
72
|
-
cookieOptions?: CookieOptions
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Supabase Client options
|
|
76
|
-
* @default {
|
|
77
|
-
auth: {
|
|
78
|
-
flowType: 'pkce',
|
|
79
|
-
detectSessionInUrl: true,
|
|
80
|
-
persistSession: true,
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
* @type object
|
|
84
|
-
* @docs https://supabase.com/docs/reference/javascript/initializing#parameters
|
|
85
|
-
*/
|
|
86
|
-
clientOptions?: SupabaseClientOptions<string>
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface RedirectOptions {
|
|
90
|
-
/**
|
|
91
|
-
* Login route
|
|
92
|
-
* @default '/login'
|
|
93
|
-
* @type string
|
|
94
|
-
*/
|
|
95
|
-
login?: string
|
|
96
|
-
/**
|
|
97
|
-
* Routes to exclude from redirection
|
|
98
|
-
* @default []
|
|
99
|
-
* @type string[]
|
|
100
|
-
*/
|
|
101
|
-
exclude?: string[]
|
|
102
|
-
}
|
|
File without changes
|
|
File without changes
|