@witchcraft/nuxt-auth 0.0.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 +693 -0
- package/dist/module.d.mts +170 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +146 -0
- package/dist/runtime/build/genAuthSecretKeys.d.ts +6 -0
- package/dist/runtime/build/genAuthSecretKeys.js +10 -0
- package/dist/runtime/components/ExternalCallback.d.vue.ts +7 -0
- package/dist/runtime/components/ExternalCallback.vue +96 -0
- package/dist/runtime/components/ExternalCallback.vue.d.ts +7 -0
- package/dist/runtime/components/ExternalCode.d.vue.ts +11 -0
- package/dist/runtime/components/ExternalCode.vue +77 -0
- package/dist/runtime/components/ExternalCode.vue.d.ts +11 -0
- package/dist/runtime/components/LoginProviderButtons.client.d.vue.ts +15 -0
- package/dist/runtime/components/LoginProviderButtons.client.vue +66 -0
- package/dist/runtime/components/LoginProviderButtons.client.vue.d.ts +15 -0
- package/dist/runtime/components/Mocker.d.vue.ts +2 -0
- package/dist/runtime/components/Mocker.vue +39 -0
- package/dist/runtime/components/Mocker.vue.d.ts +2 -0
- package/dist/runtime/components/SessionStatus.d.vue.ts +35 -0
- package/dist/runtime/components/SessionStatus.vue +85 -0
- package/dist/runtime/components/SessionStatus.vue.d.ts +35 -0
- package/dist/runtime/components/UserRegistration.d.vue.ts +35 -0
- package/dist/runtime/components/UserRegistration.vue +158 -0
- package/dist/runtime/components/UserRegistration.vue.d.ts +35 -0
- package/dist/runtime/composables/useAuth.d.ts +27 -0
- package/dist/runtime/composables/useAuth.js +73 -0
- package/dist/runtime/core/providerStyles.d.ts +2 -0
- package/dist/runtime/core/providerStyles.js +6 -0
- package/dist/runtime/core/providers/github.d.ts +89 -0
- package/dist/runtime/core/providers/github.js +60 -0
- package/dist/runtime/core/providers/google.d.ts +70 -0
- package/dist/runtime/core/providers/google.js +54 -0
- package/dist/runtime/middleware/authGlobal.d.ts +2 -0
- package/dist/runtime/middleware/authGlobal.js +34 -0
- package/dist/runtime/middleware/authProtected.d.ts +2 -0
- package/dist/runtime/middleware/authProtected.js +38 -0
- package/dist/runtime/server/helpers/getSafeSecretsInfo.d.ts +4 -0
- package/dist/runtime/server/helpers/getSafeSecretsInfo.js +10 -0
- package/dist/runtime/server/helpers/logSafeRoute.d.ts +1 -0
- package/dist/runtime/server/helpers/logSafeRoute.js +3 -0
- package/dist/runtime/server/helpers/signJwt.d.ts +5 -0
- package/dist/runtime/server/helpers/signJwt.js +16 -0
- package/dist/runtime/server/helpers/verifyJwt.d.ts +5 -0
- package/dist/runtime/server/helpers/verifyJwt.js +19 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/Auth.d.ts +83 -0
- package/dist/runtime/server/utils/Auth.js +653 -0
- package/dist/runtime/server/utils/SessionManager.d.ts +25 -0
- package/dist/runtime/server/utils/SessionManager.js +93 -0
- package/dist/runtime/server/utils/createAuthHandler.d.ts +8 -0
- package/dist/runtime/server/utils/createAuthHandler.js +29 -0
- package/dist/runtime/server/utils/createAuthMiddleware.d.ts +10 -0
- package/dist/runtime/server/utils/createAuthMiddleware.js +28 -0
- package/dist/runtime/server/utils/createAuthSchema.d.ts +244 -0
- package/dist/runtime/server/utils/createAuthSchema.js +43 -0
- package/dist/runtime/types.d.ts +239 -0
- package/dist/runtime/types.js +15 -0
- package/dist/runtime/utils/createExternalAuthHandler.d.ts +36 -0
- package/dist/runtime/utils/createExternalAuthHandler.js +25 -0
- package/dist/runtime/utils/decodeQueryUri.d.ts +2 -0
- package/dist/runtime/utils/decodeQueryUri.js +4 -0
- package/dist/runtime/utils/getAuthApiRoute.d.ts +3 -0
- package/dist/runtime/utils/getAuthApiRoute.js +14 -0
- package/dist/types.d.mts +13 -0
- package/package.json +101 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { CookieSerializeOptions } from 'cookie-es';
|
|
3
|
+
import { Secrets, ProviderNames, SessionCookieOptions, AdditionalApiRoutes } from '../dist/runtime/types.js';
|
|
4
|
+
export * from '../dist/runtime/types.js';
|
|
5
|
+
export * from '../dist/runtime/server/utils/createAuthSchema.js';
|
|
6
|
+
import { useAuth } from '../dist/runtime/composables/useAuth.js';
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
}
|
|
10
|
+
declare module "vue-router" {
|
|
11
|
+
interface RouteMeta {
|
|
12
|
+
auth?: {
|
|
13
|
+
keepQuery?: boolean | string[];
|
|
14
|
+
/**
|
|
15
|
+
* Only allow users on the page that match the given conditions.
|
|
16
|
+
*/
|
|
17
|
+
only?: "authenticated" | "authenticated-registered" | "registered" | "authenticated-unregistered" | "unauthenticated" | ((auth: ReturnType<typeof useAuth>) => boolean);
|
|
18
|
+
/** Path to redirect to. Can be a magic path like "$login" or "$register". */
|
|
19
|
+
redirectTo?: string | "$login" | "$register" | "$postRegisteredLogin" | "$externalCode" | (() => string);
|
|
20
|
+
handleRedirect?: (url: string) => void | Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
interface ModuleOptions {
|
|
25
|
+
enabledProviders: ProviderNames[];
|
|
26
|
+
useGlobalMiddleware: boolean;
|
|
27
|
+
onlySaveUnregisteredUserAccountInfo: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Options for the provider cookies.
|
|
30
|
+
*
|
|
31
|
+
* `secure` is not included in the options because it's determined by whether `useRuntimeConfig().public.auth.isSecure` was defined (which this module sets automatically).
|
|
32
|
+
*
|
|
33
|
+
* @default {
|
|
34
|
+
* maxAge: 60 * 10, // 10 minutes
|
|
35
|
+
* sameSite: "lax" as const,
|
|
36
|
+
* httpOnly: true,
|
|
37
|
+
* path: "/",
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
providerCookieOpts: Omit<Partial<CookieSerializeOptions>, "secure">;
|
|
41
|
+
/**
|
|
42
|
+
* The number of milliseconds the session cookie expires after.
|
|
43
|
+
*
|
|
44
|
+
* Can also be overriden when creating the `SessionManager`.
|
|
45
|
+
*
|
|
46
|
+
* @default 1000 * 60 * 60 * 24 * 30 // 30 days
|
|
47
|
+
*/
|
|
48
|
+
sessionExpiresAt: number;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* Options for the session cookie.
|
|
52
|
+
*
|
|
53
|
+
* Can also be overriden when creating the `SessionManager`.
|
|
54
|
+
*
|
|
55
|
+
* `secure` is not included in the options because it's determined by whether `useRuntimeConfig().public.auth.isSecure` was defined (which this module sets automatically).
|
|
56
|
+
*
|
|
57
|
+
* @default {
|
|
58
|
+
* sameSite: "lax" as const,
|
|
59
|
+
* httpOnly: true,
|
|
60
|
+
* path: "/",
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
sessionCookieOpts: Omit<SessionCookieOptions, "maxAge" | "secure" | "expiresAt">;
|
|
64
|
+
authRoutes: Partial<{
|
|
65
|
+
/**
|
|
66
|
+
* When the user tries to go to a protected route, they will be redirected here.
|
|
67
|
+
*
|
|
68
|
+
* @default "/"
|
|
69
|
+
*/
|
|
70
|
+
unauthenticated: string;
|
|
71
|
+
/**
|
|
72
|
+
* The route for the login page.
|
|
73
|
+
*
|
|
74
|
+
* @default "/auth/login"
|
|
75
|
+
*
|
|
76
|
+
* The path is also used to redirect unauthenticated users in the protected routes.
|
|
77
|
+
*/
|
|
78
|
+
login: string;
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* For redirecting the user after login if they aren't registered yet.
|
|
82
|
+
*
|
|
83
|
+
* @default "/auth/register"
|
|
84
|
+
*
|
|
85
|
+
* Also used to redirect un-registered authenticated users in the protected routes.
|
|
86
|
+
*/
|
|
87
|
+
register: string;
|
|
88
|
+
/**
|
|
89
|
+
* After a registered user finishes registration, or when an existing user logs in, they will be redirected here.
|
|
90
|
+
*
|
|
91
|
+
* @default "/"
|
|
92
|
+
*/
|
|
93
|
+
postRegisteredLogin: string;
|
|
94
|
+
/**
|
|
95
|
+
* The route to redirect to once a user has been authenticated and registered when the deeplink query param is passed.
|
|
96
|
+
*
|
|
97
|
+
* See the External Auth Handlers section of the README for more info.
|
|
98
|
+
*
|
|
99
|
+
* @default "/auth/code"
|
|
100
|
+
*/
|
|
101
|
+
externalCode: string;
|
|
102
|
+
/**
|
|
103
|
+
* The url to open from `/auth/code`. It is appended to the deeplink scheme (see {@link Auth.deepLinkSchemes}) and the accessToken will be appended to it.
|
|
104
|
+
*
|
|
105
|
+
* How opening it is handled is up to the app, but the idea is it's a single page that can handle receiving the code via a query param or manually (a component, `AuthExternalCallback` is provided for this purpose).
|
|
106
|
+
*
|
|
107
|
+
* @default `/auth/external/callback`
|
|
108
|
+
*/
|
|
109
|
+
deeplink: string;
|
|
110
|
+
/**
|
|
111
|
+
* The route that handles mocking the OAuth flow for development purposes.
|
|
112
|
+
*
|
|
113
|
+
* @default `/auth/mock`
|
|
114
|
+
*/
|
|
115
|
+
mockAuth: string;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* The routes for the api calls.
|
|
119
|
+
*
|
|
120
|
+
* If you stick to using these as variables from the runtime config, you can change them so long as you don't rename the dynamic parts:
|
|
121
|
+
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* fetch(`${useRuntimeConfig().public.auth.authApiRoutes.usersInfo}`)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
authApiRoutes: Partial<{
|
|
127
|
+
/** @default "/api/auth" */
|
|
128
|
+
base: string;
|
|
129
|
+
/** @default "/users/info" */
|
|
130
|
+
usersInfo: string;
|
|
131
|
+
/** @default "/external/exchange" */
|
|
132
|
+
externalExchange: string;
|
|
133
|
+
/** @default "/users/:id/accounts" */
|
|
134
|
+
usersIdAccounts: string;
|
|
135
|
+
/** @default "/logout" */
|
|
136
|
+
logout: string;
|
|
137
|
+
/** @default "/login/:provider" */
|
|
138
|
+
login: string;
|
|
139
|
+
/** @default "/register" */
|
|
140
|
+
register: string;
|
|
141
|
+
/** @default "/callback/:provider" */
|
|
142
|
+
callback: string;
|
|
143
|
+
/**
|
|
144
|
+
* Note the route is NOT defined by the module, you must extend the routes and define it yourself if you are using the UserRegistration component which makes use of it.
|
|
145
|
+
*
|
|
146
|
+
* @default "/api/auth/public/users/:username/valid"
|
|
147
|
+
*/
|
|
148
|
+
usernameValid: string;
|
|
149
|
+
}> & Partial<AdditionalApiRoutes>;
|
|
150
|
+
/** Additional "magic" paths that can be used for the `auth.redirectTo` page meta property when using the `authProtected` middleware. */
|
|
151
|
+
additionalMiddlewarePaths?: Record<string, string>;
|
|
152
|
+
}
|
|
153
|
+
interface ModulePublicRuntimeConfig {
|
|
154
|
+
auth: Required<Omit<ModuleOptions, "useGlobalMiddleware" | "authRoutes" | "authApiRoutes">> & {
|
|
155
|
+
authRoutes: Required<ModuleOptions>["authRoutes"];
|
|
156
|
+
authApiRoutes: Required<ModuleOptions["authApiRoutes"]>;
|
|
157
|
+
isSecure: boolean;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
declare module "@nuxt/schema" {
|
|
161
|
+
interface RuntimeConfig extends Secrets {
|
|
162
|
+
authSecret: string;
|
|
163
|
+
}
|
|
164
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
168
|
+
|
|
169
|
+
export { _default as default };
|
|
170
|
+
export type { ModuleOptions, ModulePublicRuntimeConfig };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { crop } from '@alanscodelog/utils/crop';
|
|
2
|
+
import { defineNuxtModule, useLogger, createResolver, addComponentsDir, addImportsDir, addServerScanDir, addServerImportsDir, addServerImports, addTemplate, addRouteMiddleware } from '@nuxt/kit';
|
|
3
|
+
import { defu } from 'defu';
|
|
4
|
+
|
|
5
|
+
const dependencies = {
|
|
6
|
+
"@witchcraft/ui": "^0.2.3",
|
|
7
|
+
"nuxt-security": "^2.4.0"};
|
|
8
|
+
const pkg = {
|
|
9
|
+
dependencies: dependencies};
|
|
10
|
+
|
|
11
|
+
const module = defineNuxtModule({
|
|
12
|
+
meta: {
|
|
13
|
+
name: "auth",
|
|
14
|
+
configKey: "auth"
|
|
15
|
+
},
|
|
16
|
+
defaults: {
|
|
17
|
+
useGlobalMiddleware: true,
|
|
18
|
+
providerCookieOpts: {
|
|
19
|
+
httpOnly: true,
|
|
20
|
+
path: "/",
|
|
21
|
+
maxAge: 60 * 10,
|
|
22
|
+
// 10 minutes
|
|
23
|
+
sameSite: "lax"
|
|
24
|
+
},
|
|
25
|
+
sessionExpiresAt: 1e3 * 60 * 60 * 24 * 30,
|
|
26
|
+
sessionCookieOpts: {
|
|
27
|
+
sameSite: "lax",
|
|
28
|
+
httpOnly: true,
|
|
29
|
+
path: "/"
|
|
30
|
+
},
|
|
31
|
+
enabledProviders: [
|
|
32
|
+
"google",
|
|
33
|
+
"github"
|
|
34
|
+
],
|
|
35
|
+
authRoutes: {
|
|
36
|
+
login: "/auth/login",
|
|
37
|
+
register: "/auth/register",
|
|
38
|
+
unauthenticated: "/",
|
|
39
|
+
postRegisteredLogin: "/",
|
|
40
|
+
externalCode: "/auth/code",
|
|
41
|
+
deeplink: "/auth/external/callback",
|
|
42
|
+
mockAuth: "/auth/mock"
|
|
43
|
+
},
|
|
44
|
+
authApiRoutes: {
|
|
45
|
+
base: "/api/auth",
|
|
46
|
+
usersInfo: "/users/info",
|
|
47
|
+
externalExchange: "/external/exchange",
|
|
48
|
+
usersIdAccounts: "/users/:id/accounts",
|
|
49
|
+
logout: "/logout",
|
|
50
|
+
login: "/login/:provider",
|
|
51
|
+
callback: "/callback/:provider",
|
|
52
|
+
register: "/register",
|
|
53
|
+
usernameValid: "/public/users/:username/valid"
|
|
54
|
+
},
|
|
55
|
+
onlySaveUnregisteredUserAccountInfo: false,
|
|
56
|
+
additionalMiddlewarePaths: {}
|
|
57
|
+
},
|
|
58
|
+
moduleDependencies: {
|
|
59
|
+
"@witchcraft/ui": {
|
|
60
|
+
version: pkg.dependencies["@witchcraft/ui"],
|
|
61
|
+
optional: true
|
|
62
|
+
},
|
|
63
|
+
"nuxt-security": {
|
|
64
|
+
version: pkg.dependencies["nuxt-security"],
|
|
65
|
+
optional: true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
async setup(options, nuxt) {
|
|
69
|
+
const moduleName = "@witchcraft/nuxt-auth";
|
|
70
|
+
const logger = useLogger(moduleName);
|
|
71
|
+
const { resolve } = createResolver(import.meta.url);
|
|
72
|
+
addComponentsDir({
|
|
73
|
+
path: resolve("runtime/components"),
|
|
74
|
+
prefix: "Auth",
|
|
75
|
+
global: true
|
|
76
|
+
});
|
|
77
|
+
if (!process.env.NUXT_AUTH_SECRET) {
|
|
78
|
+
logger.error("Missing $NUXT_AUTH_SECRET.");
|
|
79
|
+
}
|
|
80
|
+
if (process.env.NUXT_AUTH_SECRET && process.env.NUXT_AUTH_SECRET.length === 0) {
|
|
81
|
+
logger.warn("$NUXT_AUTH_SECRET is empty. This is not recommended.");
|
|
82
|
+
}
|
|
83
|
+
nuxt.options.runtimeConfig.public.auth = defu(
|
|
84
|
+
nuxt.options.runtimeConfig.public.auth,
|
|
85
|
+
{
|
|
86
|
+
isSecure: !!nuxt.options.devServer.https || process.env.mode === "production"
|
|
87
|
+
},
|
|
88
|
+
options
|
|
89
|
+
);
|
|
90
|
+
delete nuxt.options.runtimeConfig.public.auth.useGlobalMiddleware;
|
|
91
|
+
nuxt.options.alias["#auth"] = resolve("runtime");
|
|
92
|
+
addImportsDir(resolve("runtime/composables"));
|
|
93
|
+
addImportsDir(resolve("runtime/utils"));
|
|
94
|
+
addServerScanDir(resolve("runtime/server"));
|
|
95
|
+
addServerImportsDir(resolve("runtime/server/utils"));
|
|
96
|
+
addServerImports([
|
|
97
|
+
{
|
|
98
|
+
name: "getAuthApiRoute",
|
|
99
|
+
from: resolve("runtime/utils/getAuthApiRoute")
|
|
100
|
+
}
|
|
101
|
+
]);
|
|
102
|
+
for (const file of [
|
|
103
|
+
// "runtime",
|
|
104
|
+
"runtime/types",
|
|
105
|
+
// why, if not transpiled import path is wrong :/
|
|
106
|
+
"runtime/server/utils/Auth",
|
|
107
|
+
"runtime/server/helpers/getSafeSecretsInfo",
|
|
108
|
+
"runtime/server/helpers/logSafeRoute",
|
|
109
|
+
"runtime/server/utils/createAuthHandler",
|
|
110
|
+
"runtime/server/utils/createAuthMiddleware",
|
|
111
|
+
"runtime/server/utils/createAuthSchema",
|
|
112
|
+
"runtime/utils/getAuthApiRoute",
|
|
113
|
+
"runtime/core/providers/google",
|
|
114
|
+
"runtime/core/providers/github",
|
|
115
|
+
"runtime/utils/createExternalAuthHandler"
|
|
116
|
+
]) {
|
|
117
|
+
nuxt.options.build.transpile.push(resolve(file));
|
|
118
|
+
}
|
|
119
|
+
addTemplate({
|
|
120
|
+
filename: "witchcraft-nuxt-auth.css",
|
|
121
|
+
write: true,
|
|
122
|
+
getContents: () => crop`
|
|
123
|
+
@source "${resolve("runtime/components")}";
|
|
124
|
+
`
|
|
125
|
+
});
|
|
126
|
+
const mockAuth = nuxt.options.runtimeConfig.public.auth.authRoutes.mockAuth;
|
|
127
|
+
if (process.env.NODE_ENV !== "development" && mockAuth) {
|
|
128
|
+
nuxt.hook("pages:extend", (pages) => {
|
|
129
|
+
const i = pages.findIndex((page) => page.path === mockAuth);
|
|
130
|
+
pages.splice(i, 1);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
addRouteMiddleware({
|
|
134
|
+
name: "authProtected",
|
|
135
|
+
path: resolve("runtime/middleware/authProtected"),
|
|
136
|
+
global: false
|
|
137
|
+
});
|
|
138
|
+
addRouteMiddleware({
|
|
139
|
+
name: "authGlobal",
|
|
140
|
+
path: resolve("runtime/middleware/authGlobal"),
|
|
141
|
+
global: options.useGlobalMiddleware
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
export { module as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { capitalize } from "@alanscodelog/utils/capitalize";
|
|
2
|
+
export function genAuthSecretKeys(providers) {
|
|
3
|
+
return {
|
|
4
|
+
authSecret: "",
|
|
5
|
+
...Object.fromEntries(providers.map((provider) => [
|
|
6
|
+
[`auth${capitalize(provider)}ClientId`, ""],
|
|
7
|
+
[`auth${capitalize(provider)}ClientSecret`, ""]
|
|
8
|
+
]).flat())
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
saveSession: (token: string) => Promise<void>;
|
|
3
|
+
successPath?: string;
|
|
4
|
+
cancelPath?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex flex-col gap-4">
|
|
3
|
+
<template v-if="authUri">
|
|
4
|
+
<div class="text-xl text-center">
|
|
5
|
+
Authorize
|
|
6
|
+
</div>
|
|
7
|
+
<div class="text-lg text-center">
|
|
8
|
+
If you are not redirected automatically, open following URL and paste the code given:
|
|
9
|
+
<NuxtLink
|
|
10
|
+
class="link-like underline"
|
|
11
|
+
:href="authUri"
|
|
12
|
+
target="_blank"
|
|
13
|
+
>
|
|
14
|
+
{{ authUri }}
|
|
15
|
+
</NuxtLink>
|
|
16
|
+
</div>
|
|
17
|
+
<WInputDeprecated
|
|
18
|
+
placeholder="Paste Code Here"
|
|
19
|
+
v-model="accessToken"
|
|
20
|
+
@update:model-value="error = void 0"
|
|
21
|
+
/>
|
|
22
|
+
<div
|
|
23
|
+
v-if="error"
|
|
24
|
+
class="border-2 border-red-500 bg-red-100 dark:bg-red-900 rounded-md p-2"
|
|
25
|
+
>
|
|
26
|
+
{{ error }}
|
|
27
|
+
</div>
|
|
28
|
+
<WButton
|
|
29
|
+
:disabled="!accessToken || accessToken.length === 0"
|
|
30
|
+
@click="authorize(accessToken)"
|
|
31
|
+
>
|
|
32
|
+
Submit
|
|
33
|
+
</WButton>
|
|
34
|
+
<WButton @click="cancel">
|
|
35
|
+
Cancel
|
|
36
|
+
</WButton>
|
|
37
|
+
</template>
|
|
38
|
+
<template v-else>
|
|
39
|
+
<div class="text-xl text-center">
|
|
40
|
+
Authorizing...
|
|
41
|
+
</div>
|
|
42
|
+
<WButton @click="authorize(initialAccessToken)">
|
|
43
|
+
Retry
|
|
44
|
+
</WButton>
|
|
45
|
+
</template>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup>
|
|
50
|
+
import { unreachable } from "@alanscodelog/utils/unreachable";
|
|
51
|
+
import { useRuntimeConfig } from "#app";
|
|
52
|
+
import {
|
|
53
|
+
navigateTo,
|
|
54
|
+
ref,
|
|
55
|
+
useRoute
|
|
56
|
+
} from "#imports";
|
|
57
|
+
import { decodeQueryUri } from "../utils/decodeQueryUri.js";
|
|
58
|
+
const props = defineProps({
|
|
59
|
+
saveSession: { type: Function, required: true },
|
|
60
|
+
successPath: { type: String, required: false },
|
|
61
|
+
cancelPath: { type: String, required: false }
|
|
62
|
+
});
|
|
63
|
+
const rc = useRuntimeConfig();
|
|
64
|
+
const query = useRoute().query;
|
|
65
|
+
const initialAccessToken = query.access_token;
|
|
66
|
+
const authUri = decodeQueryUri(query.authUri);
|
|
67
|
+
if (!authUri && typeof initialAccessToken !== "string") {
|
|
68
|
+
throw new Error(`access_token parameter is not a string, got query: ${JSON.stringify(query)}`);
|
|
69
|
+
}
|
|
70
|
+
if (!authUri && !initialAccessToken) {
|
|
71
|
+
unreachable("Server should have passed authUri or access_token.");
|
|
72
|
+
}
|
|
73
|
+
if (typeof initialAccessToken === "string") {
|
|
74
|
+
void authorize(initialAccessToken, true);
|
|
75
|
+
}
|
|
76
|
+
const accessToken = ref("");
|
|
77
|
+
const error = ref();
|
|
78
|
+
async function authorize(token, initial = false) {
|
|
79
|
+
if (!token || token.length === 0) {
|
|
80
|
+
if (!initial) {
|
|
81
|
+
error.value = "No code provided.";
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const res = await props.saveSession(token).catch((err) => {
|
|
86
|
+
error.value = err.message;
|
|
87
|
+
return err;
|
|
88
|
+
});
|
|
89
|
+
if (!(res instanceof Error)) {
|
|
90
|
+
await navigateTo(props.successPath ?? rc.public.auth.authRoutes.postRegisteredLogin);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function cancel() {
|
|
94
|
+
await navigateTo(props.cancelPath ?? rc.public.auth.authRoutes.login);
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
saveSession: (token: string) => Promise<void>;
|
|
3
|
+
successPath?: string;
|
|
4
|
+
cancelPath?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
openAppText?: string;
|
|
3
|
+
promptText?: string;
|
|
4
|
+
copyTitle?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
7
|
+
openAppText: string;
|
|
8
|
+
promptText: string;
|
|
9
|
+
copyTitle: string;
|
|
10
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex flex-col justify-center gap-4">
|
|
3
|
+
<div class="text-lg text-center">
|
|
4
|
+
{{ promptText }}
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<NuxtLink
|
|
8
|
+
class="
|
|
9
|
+
px-1
|
|
10
|
+
text-center
|
|
11
|
+
hover:shadow-xs
|
|
12
|
+
text-xl
|
|
13
|
+
border-2
|
|
14
|
+
border-accent-500
|
|
15
|
+
rounded-sm
|
|
16
|
+
hover:border-accent-400
|
|
17
|
+
|
|
18
|
+
"
|
|
19
|
+
:to="deepLinkUrl"
|
|
20
|
+
:external="true"
|
|
21
|
+
>
|
|
22
|
+
{{ openAppText }}
|
|
23
|
+
</NuxtLink>
|
|
24
|
+
<WButton
|
|
25
|
+
:title="copyTitle"
|
|
26
|
+
class="
|
|
27
|
+
text-xl
|
|
28
|
+
bg-accent-100
|
|
29
|
+
dark:bg-accent-950/50
|
|
30
|
+
rounded-sm
|
|
31
|
+
border-2
|
|
32
|
+
border-dashed
|
|
33
|
+
p-4
|
|
34
|
+
border-accent-500
|
|
35
|
+
dark:border-accent-600
|
|
36
|
+
select-text
|
|
37
|
+
after:shadow-none
|
|
38
|
+
hover:border-accent-400
|
|
39
|
+
hover:text-accent-500
|
|
40
|
+
break-all
|
|
41
|
+
"
|
|
42
|
+
@click="copy(accessToken)"
|
|
43
|
+
>
|
|
44
|
+
{{ accessToken }}
|
|
45
|
+
</WButton>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup>
|
|
50
|
+
import { unreachable } from "@alanscodelog/utils/unreachable";
|
|
51
|
+
import { copy } from "@witchcraft/ui/helpers/copy";
|
|
52
|
+
import {
|
|
53
|
+
navigateTo,
|
|
54
|
+
onMounted,
|
|
55
|
+
useRoute
|
|
56
|
+
} from "#imports";
|
|
57
|
+
import { decodeQueryUri } from "../utils/decodeQueryUri.js";
|
|
58
|
+
const query = useRoute().query;
|
|
59
|
+
const accessToken = query.access_token;
|
|
60
|
+
if (typeof accessToken !== "string") {
|
|
61
|
+
unreachable("No session_token.");
|
|
62
|
+
}
|
|
63
|
+
const deepLinkUrl = decodeQueryUri(query.deeplinkUri);
|
|
64
|
+
if (!deepLinkUrl) {
|
|
65
|
+
unreachable("No deeplinkUrl could be decoded.");
|
|
66
|
+
}
|
|
67
|
+
defineProps({
|
|
68
|
+
openAppText: { type: String, required: false, default: "Open App and Authorize" },
|
|
69
|
+
promptText: { type: String, required: false, default: "If you are not prompted to open the app, try clicking below or copy this token into the app:" },
|
|
70
|
+
copyTitle: { type: String, required: false, default: "Click to Copy" }
|
|
71
|
+
});
|
|
72
|
+
onMounted(() => {
|
|
73
|
+
if (accessToken) {
|
|
74
|
+
void navigateTo(deepLinkUrl, { external: true });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
openAppText?: string;
|
|
3
|
+
promptText?: string;
|
|
4
|
+
copyTitle?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
7
|
+
openAppText: string;
|
|
8
|
+
promptText: string;
|
|
9
|
+
copyTitle: string;
|
|
10
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useAuth } from "../composables/useAuth.js.js";
|
|
2
|
+
import type { ProviderNames, ProviderStyle, UseAuthComposableOptions } from "../types.js.js";
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
|
|
5
|
+
useAuthOptions?: UseAuthComposableOptions;
|
|
6
|
+
loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
9
|
+
providerStyles: Record<ProviderNames, Partial<ProviderStyle>>;
|
|
10
|
+
useAuthOptions: UseAuthComposableOptions;
|
|
11
|
+
loginOptions: {
|
|
12
|
+
devBypass?: boolean;
|
|
13
|
+
};
|
|
14
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="
|
|
4
|
+
flex-1
|
|
5
|
+
flex
|
|
6
|
+
flex-col
|
|
7
|
+
items-center
|
|
8
|
+
justify-center
|
|
9
|
+
gap-2
|
|
10
|
+
"
|
|
11
|
+
>
|
|
12
|
+
<template
|
|
13
|
+
v-for="provider in enabledProviders"
|
|
14
|
+
:key="provider"
|
|
15
|
+
>
|
|
16
|
+
<!-- custom id is because useId is causing hydration mismtaches :/
|
|
17
|
+
I think because of the for loop -->
|
|
18
|
+
<WButton
|
|
19
|
+
v-if="provider"
|
|
20
|
+
:id="'login-provider-' + provider"
|
|
21
|
+
type="button"
|
|
22
|
+
class="p-2 text-l"
|
|
23
|
+
:style="styles[provider]"
|
|
24
|
+
:key="provider"
|
|
25
|
+
@click="login(provider, loginOptions)"
|
|
26
|
+
>
|
|
27
|
+
<WIcon
|
|
28
|
+
v-if="styles[provider]?.logo"
|
|
29
|
+
class="px-2 text-xl"
|
|
30
|
+
>
|
|
31
|
+
<component
|
|
32
|
+
:is="styles[provider]?.logo"
|
|
33
|
+
/>
|
|
34
|
+
</WIcon>
|
|
35
|
+
Sign in / Register with {{ styles[provider]?.name ?? provider }}
|
|
36
|
+
</WButton>
|
|
37
|
+
</template>
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script setup>
|
|
42
|
+
import { useInjectedDarkMode } from "@witchcraft/ui/composables/useInjectedDarkMode";
|
|
43
|
+
import defu from "defu";
|
|
44
|
+
import { useRuntimeConfig } from "#app";
|
|
45
|
+
import { computed } from "#imports";
|
|
46
|
+
import { useAuth } from "../composables/useAuth.js";
|
|
47
|
+
import { providerStyles as baseProviderStyles } from "../core/providerStyles.js";
|
|
48
|
+
const rc = useRuntimeConfig();
|
|
49
|
+
const config = rc.public.auth;
|
|
50
|
+
const enabledProviders = config.enabledProviders;
|
|
51
|
+
const { darkMode: isDark } = useInjectedDarkMode();
|
|
52
|
+
const props = defineProps({
|
|
53
|
+
providerStyles: { type: Object, required: false, default: () => ({}) },
|
|
54
|
+
useAuthOptions: { type: Object, required: false, default: () => ({}) },
|
|
55
|
+
loginOptions: { type: null, required: false, default: () => ({}) }
|
|
56
|
+
});
|
|
57
|
+
const { login } = useAuth(props.useAuthOptions);
|
|
58
|
+
const fullProviderStyles = computed(() => defu(props.providerStyles, baseProviderStyles));
|
|
59
|
+
const styles = computed(() => Object.fromEntries(Object.entries(fullProviderStyles.value).map(([key, value]) => [key, {
|
|
60
|
+
...value,
|
|
61
|
+
style: value?.style ? {
|
|
62
|
+
backgroundColor: (isDark.value ? value.style.bgDark : value.style.bg) ?? "",
|
|
63
|
+
color: (isDark.value ? value.style.textDark : value.style.text) ?? ""
|
|
64
|
+
} : {}
|
|
65
|
+
}])));
|
|
66
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useAuth } from "../composables/useAuth.js.js";
|
|
2
|
+
import type { ProviderNames, ProviderStyle, UseAuthComposableOptions } from "../types.js.js";
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
|
|
5
|
+
useAuthOptions?: UseAuthComposableOptions;
|
|
6
|
+
loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
9
|
+
providerStyles: Record<ProviderNames, Partial<ProviderStyle>>;
|
|
10
|
+
useAuthOptions: UseAuthComposableOptions;
|
|
11
|
+
loginOptions: {
|
|
12
|
+
devBypass?: boolean;
|
|
13
|
+
};
|
|
14
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|