@floatingpixels/supabase-nuxt 0.1.8 → 0.2.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 +6 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +22 -27
- package/dist/runtime/plugins/middleware-auth-redirect.mjs +2 -2
- package/dist/runtime/plugins/supabase.client.d.ts +9 -1
- package/dist/runtime/plugins/supabase.client.mjs +2 -5
- package/dist/runtime/plugins/supabase.server.d.ts +9 -1
- package/dist/runtime/plugins/supabase.server.mjs +1 -1
- package/dist/runtime/server/auth/callback.d.ts +1 -1
- package/dist/runtime/server/auth/callback.mjs +1 -2
- package/dist/runtime/server/auth/confirm.d.ts +1 -1
- package/dist/runtime/server/auth/confirm.mjs +1 -2
- package/package.json +13 -11
- package/dist/runtime/plugins/middleware-auth.d.ts +0 -2
- package/dist/runtime/plugins/middleware-auth.mjs +0 -14
package/README.md
CHANGED
|
@@ -158,20 +158,20 @@ Once the authorization flow is triggered using the `auth` wrapper of the `useSup
|
|
|
158
158
|
|
|
159
159
|
### E-Mail Authentication
|
|
160
160
|
|
|
161
|
-
When using e-mail authentication, a confirmation e-mail is sent to new users, and an e-mail containing a magic link is sent to existing users. For those links to work with your application, you need to adjust the e-mail templates in your Supabase settings under `Authentication -> Email Templates`. The generated links must contain a `token_hash` and `type` URL parameter, and point to the confirmation URL of your app, which is `/supabase/confirm` by default. In addition you can set the URL parameter `next` to determine the route users will be forwarded to in your app when authorization is successful. If `next` is omitted, it will route to `/`. An example template looks like this:
|
|
161
|
+
When using e-mail authentication, a confirmation e-mail is sent to new users, and an e-mail containing a magic link is sent to existing users. For those links to work with your application, you need to adjust the e-mail templates in your Supabase settings under `Authentication -> Email Templates`. The generated links must contain a `token_hash` and `type` URL parameter, and point to the confirmation URL of your app, which is `/supabase/auth/confirm` by default. In addition you can set the URL parameter `next` to determine the route users will be forwarded to in your app when authorization is successful. If `next` is omitted, it will route to `/`. An example template looks like this:
|
|
162
162
|
|
|
163
163
|
```html
|
|
164
164
|
<h2>Confirm your signup</h2>
|
|
165
165
|
|
|
166
166
|
<p>Follow this link to confirm your user:</p>
|
|
167
167
|
<p>
|
|
168
|
-
<a href="{{ .SiteURL }}/supabase/confirm?token_hash={{ .TokenHash }}&type=email&next=/path-to-your-page"
|
|
168
|
+
<a href="{{ .SiteURL }}/supabase/auth/confirm?token_hash={{ .TokenHash }}&type=email&next=/path-to-your-page"
|
|
169
169
|
>Confirm your email</a
|
|
170
170
|
>
|
|
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/confirm`. It will automatically confirm the user and redirect to the `next` route.
|
|
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 redirect to the `next` route.
|
|
175
175
|
|
|
176
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 redirect to the `next` route:
|
|
177
177
|
|
|
@@ -204,14 +204,14 @@ export default defineEventHandler(async event => {
|
|
|
204
204
|
|
|
205
205
|
### OAuth Authentication
|
|
206
206
|
|
|
207
|
-
When using OAuth authentication, you need to configure the OAuth provider in your Supabase settings under `Authentication -> Providers`. You can then use the `signInWithOAuth` method of the `auth` wrapper of the `useSupabaseClient` composable to initiate the authorization flow. This module provides a default callback under `/supabase/callback` that you can provide to the authentication function:
|
|
207
|
+
When using OAuth authentication, you need to configure the OAuth provider in your Supabase settings under `Authentication -> Providers`. You can then use the `signInWithOAuth` method of the `auth` wrapper of the `useSupabaseClient` composable to initiate the authorization flow. This module provides a default callback under `/supabase/auth/callback` that you can provide to the authentication function:
|
|
208
208
|
|
|
209
209
|
```ts [pages/login.vue]
|
|
210
210
|
const signInWithOAuth = async () => {
|
|
211
211
|
const { error } = await supabase.auth.signInWithOAuth({
|
|
212
212
|
provider: 'github',
|
|
213
213
|
options: {
|
|
214
|
-
redirectTo: 'http://<your-site-url>/supabase/callback',
|
|
214
|
+
redirectTo: 'http://<your-site-url>/supabase/auth/callback',
|
|
215
215
|
},
|
|
216
216
|
})
|
|
217
217
|
if (error) console.log(error)
|
|
@@ -220,7 +220,7 @@ const signInWithOAuth = async () => {
|
|
|
220
220
|
|
|
221
221
|
You can customize the callback by creating your own server route, and point to it when calling `signInWithOAuth`. The callback route will receive a code, that needs to be exchanged for a session. Here is an example:
|
|
222
222
|
|
|
223
|
-
> ⚠️ You can use the provided callback route at `/supabase/callback`, the implementation of a custom callback is optional!
|
|
223
|
+
> ⚠️ You can use the provided callback route at `/supabase/auth/callback`, the implementation of a custom callback is optional!
|
|
224
224
|
|
|
225
225
|
```ts [server/api/callback.ts]
|
|
226
226
|
import { supabaseServerClient } from '#supabase/server'
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver,
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addTemplate, extendViteConfig } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
@@ -33,11 +33,6 @@ const module = defineNuxtModule({
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
-
// hooks: {
|
|
37
|
-
// 'pages:routerOptions': options => {
|
|
38
|
-
// console.info(`Router options: ${options}`)
|
|
39
|
-
// },
|
|
40
|
-
// },
|
|
41
36
|
setup(options, nuxt) {
|
|
42
37
|
const { resolve } = createResolver(import.meta.url);
|
|
43
38
|
if (!options.url) {
|
|
@@ -57,20 +52,21 @@ const module = defineNuxtModule({
|
|
|
57
52
|
nuxt.options.runtimeConfig.supabase = defu(nuxt.options.runtimeConfig.supabase, {
|
|
58
53
|
serviceKey: options.serviceKey
|
|
59
54
|
});
|
|
55
|
+
addServerHandler({
|
|
56
|
+
route: "/supabase/auth/confirm",
|
|
57
|
+
handler: resolve("./runtime/server/auth/confirm"),
|
|
58
|
+
method: "get"
|
|
59
|
+
});
|
|
60
|
+
addServerHandler({
|
|
61
|
+
route: "/supabase/auth/callback",
|
|
62
|
+
handler: resolve("./runtime/server/auth/callback"),
|
|
63
|
+
method: "get"
|
|
64
|
+
});
|
|
60
65
|
addPlugin(resolve("./runtime/plugins/supabase.server"));
|
|
61
66
|
addPlugin(resolve("./runtime/plugins/supabase.client"));
|
|
62
|
-
addPlugin(resolve("./runtime/plugins/middleware-auth"));
|
|
63
67
|
nuxt.hook("imports:dirs", (dirs) => {
|
|
64
68
|
dirs.push(resolve("./runtime/composables"));
|
|
65
69
|
});
|
|
66
|
-
addServerHandler({
|
|
67
|
-
route: "/supabase/confirm",
|
|
68
|
-
handler: resolve("./runtime/server/auth/confirm")
|
|
69
|
-
});
|
|
70
|
-
addServerHandler({
|
|
71
|
-
route: "/supabase/callback",
|
|
72
|
-
handler: resolve("./runtime/server/auth/callback")
|
|
73
|
-
});
|
|
74
70
|
if (options.redirect) {
|
|
75
71
|
addPlugin(resolve("./runtime/plugins/middleware-auth-redirect"));
|
|
76
72
|
}
|
|
@@ -95,18 +91,17 @@ const module = defineNuxtModule({
|
|
|
95
91
|
options2.references.push({ path: resolve(nuxt.options.buildDir, "types/supabase.d.ts") });
|
|
96
92
|
});
|
|
97
93
|
extendViteConfig((config) => {
|
|
98
|
-
config.optimizeDeps = config.optimizeDeps
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
);
|
|
94
|
+
config.optimizeDeps = defu(typeof config.optimizeDeps === "object" ? config.optimizeDeps : {}, {
|
|
95
|
+
include: [
|
|
96
|
+
"@supabase/functions-js",
|
|
97
|
+
"@supabase/gotrue-js",
|
|
98
|
+
"@supabase/postgrest-js",
|
|
99
|
+
"@supabase/realtime-js",
|
|
100
|
+
"@supabase/storage-js",
|
|
101
|
+
"@supabase/supabase-js",
|
|
102
|
+
"@supabase/ssr"
|
|
103
|
+
]
|
|
104
|
+
});
|
|
110
105
|
});
|
|
111
106
|
}
|
|
112
107
|
});
|
|
@@ -4,7 +4,7 @@ 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;
|
|
@@ -16,7 +16,7 @@ export default defineNuxtPlugin({
|
|
|
16
16
|
return;
|
|
17
17
|
const user = await useSupabaseUser();
|
|
18
18
|
if (!user) {
|
|
19
|
-
return navigateTo("/login");
|
|
19
|
+
return navigateTo("/login", { redirectCode: 302 });
|
|
20
20
|
}
|
|
21
21
|
}),
|
|
22
22
|
{ global: true }
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
2
|
+
supabase: {
|
|
3
|
+
client: import("@supabase/supabase-js").SupabaseClient<any, "public", any>;
|
|
4
|
+
};
|
|
5
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
6
|
+
supabase: {
|
|
7
|
+
client: import("@supabase/supabase-js").SupabaseClient<any, "public", any>;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
2
10
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig, useCookie } from "
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig, useCookie } from "nuxt/app";
|
|
2
2
|
import { createBrowserClient } from "@supabase/ssr";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "supabase",
|
|
@@ -12,7 +12,7 @@ export default defineNuxtPlugin({
|
|
|
12
12
|
return useCookie(name).value;
|
|
13
13
|
},
|
|
14
14
|
set(name, value) {
|
|
15
|
-
useCookie(name, cookieOptions).value = value;
|
|
15
|
+
useCookie(name, { ...cookieOptions, readonly: false }).value = value;
|
|
16
16
|
},
|
|
17
17
|
remove(key2, options) {
|
|
18
18
|
useCookie(key2, { ...options, expires: 0 }).value = "";
|
|
@@ -28,8 +28,5 @@ export default defineNuxtPlugin({
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
},
|
|
32
|
-
env: {
|
|
33
|
-
islands: false
|
|
34
31
|
}
|
|
35
32
|
});
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
2
|
+
supabase: {
|
|
3
|
+
client: import("@supabase/supabase-js").SupabaseClient<any, "public", any>;
|
|
4
|
+
};
|
|
5
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
6
|
+
supabase: {
|
|
7
|
+
client: import("@supabase/supabase-js").SupabaseClient<any, "public", any>;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
2
10
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig, useRequestEvent } from "
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig, useRequestEvent } from "nuxt/app";
|
|
2
2
|
import { createServerClient } from "@supabase/ssr";
|
|
3
3
|
import { getCookie, setCookie } from "h3";
|
|
4
4
|
export default defineNuxtPlugin({
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler } from "
|
|
2
|
-
import { createError, getQuery, sendRedirect } from "h3";
|
|
1
|
+
import { defineEventHandler, createError, getQuery, sendRedirect } from "h3";
|
|
3
2
|
import { supabaseServerClient } from "#supabase/server";
|
|
4
3
|
export default defineEventHandler(async (event) => {
|
|
5
4
|
const query = getQuery(event);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler } from "
|
|
2
|
-
import { createError, getQuery, sendRedirect } from "h3";
|
|
1
|
+
import { createError, getQuery, sendRedirect, defineEventHandler } from "h3";
|
|
3
2
|
import { supabaseServerClient } from "#supabase/server";
|
|
4
3
|
export default defineEventHandler(async (event) => {
|
|
5
4
|
const query = getQuery(event);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floatingpixels/supabase-nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Supabase module for Nuxt",
|
|
5
5
|
"repository": "floatingpixels/supabase-nuxt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,27 +44,29 @@
|
|
|
44
44
|
"test:watch": "vitest watch"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@nuxt/kit": "^3.
|
|
48
|
-
"@supabase/ssr": "^0.0
|
|
47
|
+
"@nuxt/kit": "^3.10.0",
|
|
48
|
+
"@supabase/ssr": "^0.1.0",
|
|
49
49
|
"@supabase/supabase-js": "^2.39.3",
|
|
50
50
|
"defu": "^6.1.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@nuxt/devtools": "
|
|
53
|
+
"@nuxt/devtools": "^1.0.8",
|
|
54
54
|
"@nuxt/eslint-config": "^0.2.0",
|
|
55
55
|
"@nuxt/module-builder": "^0.5.5",
|
|
56
|
-
"@nuxt/schema": "^3.
|
|
57
|
-
"@nuxt/test-utils": "^3.
|
|
58
|
-
"@types/node": "^20.11.
|
|
59
|
-
"@vue/test-utils": "^2.4.
|
|
56
|
+
"@nuxt/schema": "^3.10.0",
|
|
57
|
+
"@nuxt/test-utils": "^3.11.0",
|
|
58
|
+
"@types/node": "^20.11.15",
|
|
59
|
+
"@vue/test-utils": "^2.4.4",
|
|
60
60
|
"changelogen": "^0.5.5",
|
|
61
61
|
"eslint": "^8.56.0",
|
|
62
62
|
"eslint-config-prettier": "^9.1.0",
|
|
63
|
-
"happy-dom": "^13.3.
|
|
64
|
-
"nuxt": "^3.
|
|
63
|
+
"happy-dom": "^13.3.8",
|
|
64
|
+
"nuxt": "^3.10.0",
|
|
65
65
|
"playwright-core": "^1.41.1",
|
|
66
66
|
"prettier": "^3.2.4",
|
|
67
67
|
"release-it": "^17.0.3",
|
|
68
|
-
"
|
|
68
|
+
"typescript": "^5.3.3",
|
|
69
|
+
"vitest": "^1.2.2",
|
|
70
|
+
"vue-tsc": "^1.8.27"
|
|
69
71
|
}
|
|
70
72
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineNuxtPlugin, addRouteMiddleware, defineNuxtRouteMiddleware, navigateTo } from "#imports";
|
|
2
|
-
export default defineNuxtPlugin({
|
|
3
|
-
name: "middleware-auth",
|
|
4
|
-
setup() {
|
|
5
|
-
addRouteMiddleware(
|
|
6
|
-
"01-global-auth",
|
|
7
|
-
defineNuxtRouteMiddleware(async (to) => {
|
|
8
|
-
if (to.path.startsWith("/supabase/"))
|
|
9
|
-
navigateTo("/");
|
|
10
|
-
}),
|
|
11
|
-
{ global: true }
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
});
|