@frigear-nu/users 1.0.8 → 1.0.10
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 +19 -136
- package/dist/module.d.mts +35 -48
- package/dist/module.json +1 -1
- package/dist/module.mjs +104 -169
- package/dist/runtime/admin-menus.js +16 -0
- package/dist/runtime/app/pages/admin-user.vue +52 -0
- package/dist/runtime/app/pages/admin.vue +252 -0
- package/dist/runtime/app/tabs/Overview.d.vue.ts +11 -0
- package/dist/runtime/app/tabs/Overview.vue +206 -0
- package/dist/runtime/app/tabs/Overview.vue.d.ts +11 -0
- package/dist/runtime/app/utils/admin-user.d.ts +22 -0
- package/dist/runtime/app/utils/admin-user.js +0 -0
- package/dist/runtime/app/widgets/NewMembers.d.vue.ts +3 -0
- package/dist/runtime/app/widgets/NewMembers.vue +45 -0
- package/dist/runtime/app/widgets/NewMembers.vue.d.ts +3 -0
- package/dist/runtime/app/widgets/NewMembersStat.d.vue.ts +3 -0
- package/dist/runtime/app/widgets/NewMembersStat.vue +20 -0
- package/dist/runtime/app/widgets/NewMembersStat.vue.d.ts +3 -0
- package/dist/runtime/db/email-changes.sqlite.d.ts +202 -0
- package/dist/runtime/db/email-changes.sqlite.js +16 -0
- package/dist/runtime/db/schema.sqlite.d.ts +5 -212
- package/dist/runtime/db/schema.sqlite.js +2 -21
- package/dist/runtime/i18n/lang/da.json +65 -87
- package/dist/runtime/i18n/lang/en.json +65 -87
- package/dist/runtime/server/mcp/tools/get-my-profile.js +6 -0
- package/dist/runtime/server/routes/admin/new-members.get.js +16 -0
- package/dist/runtime/server/routes/admin/roles.get.js +4 -0
- package/dist/runtime/server/routes/admin/stats.get.js +12 -0
- package/dist/runtime/server/routes/admin/user-resend.post.js +19 -0
- package/dist/runtime/server/routes/admin/user.delete.js +21 -0
- package/dist/runtime/server/routes/admin/user.get.js +32 -0
- package/dist/runtime/server/routes/admin/user.patch.js +45 -0
- package/dist/runtime/server/routes/admin/users.get.js +59 -0
- package/dist/runtime/server/routes/admin/users.post.js +33 -0
- package/dist/runtime/server/routes/me/change-email.post.js +35 -0
- package/dist/runtime/server/routes/me/change-password.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/change-password.post.js +27 -0
- package/dist/runtime/server/routes/me/profile.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/profile.post.js +17 -0
- package/dist/runtime/server/routes/me/revert-email-change.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/revert-email-change.get.js +24 -0
- package/dist/runtime/server/routes/me/verify-email-change.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/verify-email-change.get.js +37 -0
- package/dist/runtime/server/user-store.d.ts +3 -0
- package/dist/runtime/server/user-store.js +70 -0
- package/dist/runtime/server/utils/admin.d.ts +59 -0
- package/dist/runtime/server/utils/admin.js +53 -0
- package/dist/runtime/server/utils/notifications.d.ts +16 -0
- package/dist/runtime/server/utils/notifications.js +32 -0
- package/dist/runtime/server/utils/require-user.d.ts +12 -0
- package/dist/runtime/server/utils/require-user.js +9 -0
- package/dist/runtime/utils/index.d.ts +19 -0
- package/dist/runtime/utils/index.js +11 -0
- package/dist/types.d.mts +2 -2
- package/package.json +28 -16
- package/dist/runtime/app/composables/useAuthManifest.d.ts +0 -5
- package/dist/runtime/app/composables/useAuthManifest.js +0 -7
- package/dist/runtime/app/composables/useUserLogin.d.ts +0 -12
- package/dist/runtime/app/composables/useUserLogin.js +0 -26
- package/dist/runtime/app/composables/useUserPasskeys.d.ts +0 -7
- package/dist/runtime/app/composables/useUserPasskeys.js +0 -22
- package/dist/runtime/app/composables/useUserPasswordReset.d.ts +0 -13
- package/dist/runtime/app/composables/useUserPasswordReset.js +0 -32
- package/dist/runtime/app/composables/useUserRegistration.d.ts +0 -10
- package/dist/runtime/app/composables/useUserRegistration.js +0 -20
- package/dist/runtime/app/pages/login.vue +0 -68
- package/dist/runtime/app/pages/register.vue +0 -40
- package/dist/runtime/app/utils/oauth-providers.d.ts +0 -13
- package/dist/runtime/app/utils/oauth-providers.js +0 -4
- package/dist/runtime/menus.js +0 -14
- package/dist/runtime/server/routes/auth/forgot-password.post.js +0 -19
- package/dist/runtime/server/routes/auth/github.get.js +0 -7
- package/dist/runtime/server/routes/auth/google.get.js +0 -6
- package/dist/runtime/server/routes/auth/login.post.js +0 -15
- package/dist/runtime/server/routes/auth/logout.get.js +0 -4
- package/dist/runtime/server/routes/auth/register.post.js +0 -18
- package/dist/runtime/server/routes/auth/reset-password.post.js +0 -29
- package/dist/runtime/server/routes/auth/webauthn/authenticate.post.js +0 -34
- package/dist/runtime/server/routes/auth/webauthn/credentials/[id].delete.js +0 -9
- package/dist/runtime/server/routes/auth/webauthn/credentials/index.get.js +0 -8
- package/dist/runtime/server/routes/auth/webauthn/register.post.js +0 -42
- package/dist/runtime/server/utils/oauth.d.ts +0 -8
- package/dist/runtime/server/utils/oauth.js +0 -18
- package/dist/runtime/server/utils/password-reset.d.ts +0 -22
- package/dist/runtime/server/utils/password-reset.js +0 -14
- package/dist/runtime/server/utils/session.d.ts +0 -11
- package/dist/runtime/server/utils/session.js +0 -5
- /package/dist/runtime/{menus.d.ts → admin-menus.d.ts} +0 -0
- /package/dist/runtime/app/pages/{login.d.vue.ts → admin-user.d.vue.ts} +0 -0
- /package/dist/runtime/app/pages/{login.vue.d.ts → admin-user.vue.d.ts} +0 -0
- /package/dist/runtime/app/pages/{register.d.vue.ts → admin.d.vue.ts} +0 -0
- /package/dist/runtime/app/pages/{register.vue.d.ts → admin.vue.d.ts} +0 -0
- /package/dist/runtime/server/{routes/auth/forgot-password.post.d.ts → mcp/tools/get-my-profile.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/github.get.d.ts → admin/new-members.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/google.get.d.ts → admin/roles.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/login.post.d.ts → admin/stats.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/logout.get.d.ts → admin/user-resend.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/register.post.d.ts → admin/user.delete.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/reset-password.post.d.ts → admin/user.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/authenticate.post.d.ts → admin/user.patch.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/credentials/[id].delete.d.ts → admin/users.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/credentials/index.get.d.ts → admin/users.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/register.post.d.ts → me/change-email.post.d.ts} +0 -0
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
defineOptions({ name: "UsersRegisterPage" });
|
|
3
|
-
const t = useModuleT("auth");
|
|
4
|
-
const { register, pending, error } = useUserRegistration();
|
|
5
|
-
const fields = computed(() => [
|
|
6
|
-
{ name: "name", type: "text", label: t("name.label", "Name"), required: true },
|
|
7
|
-
{ name: "email", type: "text", label: t("email.label", "Email"), required: true },
|
|
8
|
-
{ name: "password", type: "password", label: t("password.label", "Password"), required: true }
|
|
9
|
-
]);
|
|
10
|
-
async function onSubmit(payload) {
|
|
11
|
-
await register(payload.data);
|
|
12
|
-
await navigateTo("/");
|
|
13
|
-
}
|
|
14
|
-
</script>
|
|
15
|
-
|
|
16
|
-
<template>
|
|
17
|
-
<UContainer>
|
|
18
|
-
<UPage>
|
|
19
|
-
<UPageBody>
|
|
20
|
-
<UAuthForm
|
|
21
|
-
:title="t('signUp', 'Register')"
|
|
22
|
-
:fields="fields"
|
|
23
|
-
:loading="pending"
|
|
24
|
-
:submit="{ label: t('signUp', 'Register') }"
|
|
25
|
-
@submit="onSubmit"
|
|
26
|
-
>
|
|
27
|
-
<template
|
|
28
|
-
v-if="error"
|
|
29
|
-
#validation
|
|
30
|
-
>
|
|
31
|
-
<UAlert
|
|
32
|
-
color="error"
|
|
33
|
-
:title="error"
|
|
34
|
-
/>
|
|
35
|
-
</template>
|
|
36
|
-
</UAuthForm>
|
|
37
|
-
</UPageBody>
|
|
38
|
-
</UPage>
|
|
39
|
-
</UContainer>
|
|
40
|
-
</template>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const OAUTH_PROVIDER_META: {
|
|
2
|
-
readonly github: {
|
|
3
|
-
readonly label: "GitHub";
|
|
4
|
-
readonly icon: "i-simple-icons-github";
|
|
5
|
-
readonly to: "/api/auth/github";
|
|
6
|
-
};
|
|
7
|
-
readonly google: {
|
|
8
|
-
readonly label: "Google";
|
|
9
|
-
readonly icon: "i-simple-icons-google";
|
|
10
|
-
readonly to: "/api/auth/google";
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type OAuthProviderKey = keyof typeof OAUTH_PROVIDER_META;
|
package/dist/runtime/menus.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineMenuSource, extendMenuItem } from "@frigear-nu/menu/utils";
|
|
2
|
-
export default defineMenuSource(() => {
|
|
3
|
-
extendMenuItem("account.dropdown", {
|
|
4
|
-
id: "logout",
|
|
5
|
-
label: "Logout",
|
|
6
|
-
labelKey: "users.menu.logout.label",
|
|
7
|
-
description: "Sign out of your account.",
|
|
8
|
-
descriptionKey: "users.menu.logout.description",
|
|
9
|
-
icon: "i-lucide-log-out",
|
|
10
|
-
to: "/auth/logout",
|
|
11
|
-
external: true,
|
|
12
|
-
order: 99
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
const bodySchema = z.object({
|
|
4
|
-
email: z.string().email()
|
|
5
|
-
});
|
|
6
|
-
const RESET_CODE_TTL_MINUTES = 30;
|
|
7
|
-
export default defineEventHandler(async (event) => {
|
|
8
|
-
const { email } = await readValidatedBody(event, bodySchema.parse);
|
|
9
|
-
const user = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.email, email) });
|
|
10
|
-
if (!user) {
|
|
11
|
-
return { ok: true };
|
|
12
|
-
}
|
|
13
|
-
const code = createPasswordResetCode();
|
|
14
|
-
const expiresAt = new Date(Date.now() + RESET_CODE_TTL_MINUTES * 60 * 1e3);
|
|
15
|
-
await db.insert(schema.passwordResets).values({ userId: user.id, code, expiresAt });
|
|
16
|
-
const resetUrl = new URL(`/reset-password?code=${code}`, getRequestURL(event).origin).toString();
|
|
17
|
-
await dispatchPasswordResetEmail({ to: user.email, resetUrl });
|
|
18
|
-
return { ok: true };
|
|
19
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { db } from "@nuxthub/db";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
const bodySchema = z.object({
|
|
4
|
-
email: z.string().email(),
|
|
5
|
-
password: z.string().min(1)
|
|
6
|
-
});
|
|
7
|
-
export default defineEventHandler(async (event) => {
|
|
8
|
-
const { email, password } = await readValidatedBody(event, bodySchema.parse);
|
|
9
|
-
const user = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.email, email) });
|
|
10
|
-
if (!user?.password || !await verifyPassword(user.password, password)) {
|
|
11
|
-
throw createError({ statusCode: 401, statusMessage: "Invalid email or password." });
|
|
12
|
-
}
|
|
13
|
-
await setUserSession(event, { user: mapUserToSession(user) });
|
|
14
|
-
return { id: user.id };
|
|
15
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
const bodySchema = z.object({
|
|
4
|
-
name: z.string().min(1),
|
|
5
|
-
email: z.string().email(),
|
|
6
|
-
password: z.string().min(8)
|
|
7
|
-
});
|
|
8
|
-
export default defineEventHandler(async (event) => {
|
|
9
|
-
const { name, email, password } = await readValidatedBody(event, bodySchema.parse);
|
|
10
|
-
const existing = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.email, email) });
|
|
11
|
-
if (existing) {
|
|
12
|
-
throw createError({ statusCode: 409, statusMessage: "A user with this email already exists." });
|
|
13
|
-
}
|
|
14
|
-
const hashed = await hashPassword(password);
|
|
15
|
-
const [user] = await db.insert(schema.users).values({ name, email, password: hashed }).returning();
|
|
16
|
-
await setUserSession(event, { user: mapUserToSession(user) });
|
|
17
|
-
return { id: user.id };
|
|
18
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { and, eq, gt, isNull } from "drizzle-orm";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
const bodySchema = z.object({
|
|
5
|
-
code: z.string().min(1),
|
|
6
|
-
password: z.string().min(8),
|
|
7
|
-
confirmPassword: z.string().min(8)
|
|
8
|
-
}).refine((data) => data.password === data.confirmPassword, {
|
|
9
|
-
message: "Passwords do not match.",
|
|
10
|
-
path: ["confirmPassword"]
|
|
11
|
-
});
|
|
12
|
-
export default defineEventHandler(async (event) => {
|
|
13
|
-
const { code, password } = await readValidatedBody(event, bodySchema.parse);
|
|
14
|
-
const [passwordReset] = await db.update(schema.passwordResets).set({ usedAt: /* @__PURE__ */ new Date() }).where(and(
|
|
15
|
-
eq(schema.passwordResets.code, code),
|
|
16
|
-
isNull(schema.passwordResets.usedAt),
|
|
17
|
-
gt(schema.passwordResets.expiresAt, /* @__PURE__ */ new Date())
|
|
18
|
-
)).returning();
|
|
19
|
-
if (!passwordReset) {
|
|
20
|
-
throw createError({ statusCode: 400, statusMessage: "This password reset link is invalid or has expired." });
|
|
21
|
-
}
|
|
22
|
-
const hashed = await hashPassword(password);
|
|
23
|
-
const [user] = await db.update(schema.users).set({ password: hashed }).where(eq(schema.users.id, passwordReset.userId)).returning();
|
|
24
|
-
if (!user) {
|
|
25
|
-
throw createError({ statusCode: 404, statusMessage: "User not found." });
|
|
26
|
-
}
|
|
27
|
-
await setUserSession(event, { user: mapUserToSession(user) });
|
|
28
|
-
return { id: user.id };
|
|
29
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { eq } from "drizzle-orm";
|
|
3
|
-
export default defineWebAuthnAuthenticateEventHandler({
|
|
4
|
-
async storeChallenge(_event, challenge, attemptId) {
|
|
5
|
-
await useStorage().setItem(`attempt:${attemptId}`, challenge);
|
|
6
|
-
},
|
|
7
|
-
async getChallenge(_event, attemptId) {
|
|
8
|
-
const storage = useStorage();
|
|
9
|
-
const key = `attempt:${attemptId}`;
|
|
10
|
-
const challenge = await storage.getItem(key);
|
|
11
|
-
await storage.removeItem(key);
|
|
12
|
-
if (!challenge) throw createError({ statusCode: 400, statusMessage: "Challenge expired." });
|
|
13
|
-
return challenge;
|
|
14
|
-
},
|
|
15
|
-
async allowCredentials(_event, userName) {
|
|
16
|
-
if (!userName) return [];
|
|
17
|
-
const user = await db.query.users.findFirst({ where: (t, { eq: eq2 }) => eq2(t.email, userName) });
|
|
18
|
-
if (!user) throw createError({ statusCode: 400, statusMessage: "User not found." });
|
|
19
|
-
const credentials = await db.query.userCredentials.findMany({ where: (t, { eq: eq2 }) => eq2(t.userId, user.id) });
|
|
20
|
-
if (!credentials.length) throw createError({ statusCode: 400, statusMessage: "No passkeys registered for this user." });
|
|
21
|
-
return credentials.map((credential) => ({ id: credential.id }));
|
|
22
|
-
},
|
|
23
|
-
async getCredential(_event, credentialId) {
|
|
24
|
-
const credential = await db.query.userCredentials.findFirst({ where: (t, { eq: eq2 }) => eq2(t.id, credentialId) });
|
|
25
|
-
if (!credential) throw createError({ statusCode: 400, statusMessage: "Credential not found." });
|
|
26
|
-
return credential;
|
|
27
|
-
},
|
|
28
|
-
async onSuccess(event, { credential, authenticationInfo }) {
|
|
29
|
-
await db.update(schema.userCredentials).set({ counter: authenticationInfo.newCounter }).where(eq(schema.userCredentials.id, credential.id));
|
|
30
|
-
const dbUser = await db.query.users.findFirst({ where: (t, { eq: eq2 }) => eq2(t.id, credential.userId) });
|
|
31
|
-
if (!dbUser) throw createError({ statusCode: 400, statusMessage: "User not found." });
|
|
32
|
-
await setUserSession(event, { user: mapUserToSession(dbUser) });
|
|
33
|
-
}
|
|
34
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { and, eq } from "drizzle-orm";
|
|
3
|
-
export default defineEventHandler(async (event) => {
|
|
4
|
-
const { user } = await requireUserSession(event);
|
|
5
|
-
const id = getRouterParam(event, "id");
|
|
6
|
-
if (!id) throw createError({ statusCode: 400, statusMessage: "Missing credential id." });
|
|
7
|
-
await db.delete(schema.userCredentials).where(and(eq(schema.userCredentials.id, id), eq(schema.userCredentials.userId, user.id)));
|
|
8
|
-
return { success: true };
|
|
9
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { db } from "@nuxthub/db";
|
|
2
|
-
export default defineEventHandler(async (event) => {
|
|
3
|
-
const { user } = await requireUserSession(event);
|
|
4
|
-
return db.query.userCredentials.findMany({
|
|
5
|
-
where: (t, { eq }) => eq(t.userId, user.id),
|
|
6
|
-
columns: { publicKey: false }
|
|
7
|
-
});
|
|
8
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
export default defineWebAuthnRegisterEventHandler({
|
|
4
|
-
async storeChallenge(_event, challenge, attemptId) {
|
|
5
|
-
await useStorage().setItem(`webauthn:registration:${attemptId}`, challenge);
|
|
6
|
-
},
|
|
7
|
-
async getChallenge(_event, attemptId) {
|
|
8
|
-
const key = `webauthn:registration:${attemptId}`;
|
|
9
|
-
const challenge = await useStorage().getItem(key);
|
|
10
|
-
await useStorage().removeItem(key);
|
|
11
|
-
if (!challenge) throw createError({ statusCode: 400, statusMessage: "Registration challenge expired." });
|
|
12
|
-
return challenge;
|
|
13
|
-
},
|
|
14
|
-
async validateUser(userBody, event) {
|
|
15
|
-
const session = await getUserSession(event);
|
|
16
|
-
if (session.user?.email && session.user.email !== userBody.userName) {
|
|
17
|
-
throw createError({ statusCode: 400, statusMessage: "Email does not match the current session." });
|
|
18
|
-
}
|
|
19
|
-
return z.object({ userName: z.string().email() }).parse(userBody);
|
|
20
|
-
},
|
|
21
|
-
async onSuccess(event, { credential, user }) {
|
|
22
|
-
let dbUser = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.email, user.userName) });
|
|
23
|
-
if (dbUser) {
|
|
24
|
-
const session = await getUserSession(event);
|
|
25
|
-
if (session.user?.email !== dbUser.email) {
|
|
26
|
-
throw createError({ statusCode: 403, statusMessage: "Authenticate before adding a passkey to this account." });
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
const [created] = await db.insert(schema.users).values({ name: user.userName, email: user.userName }).returning();
|
|
30
|
-
dbUser = created;
|
|
31
|
-
}
|
|
32
|
-
await db.insert(schema.userCredentials).values({
|
|
33
|
-
id: credential.id,
|
|
34
|
-
userId: dbUser.id,
|
|
35
|
-
publicKey: credential.publicKey,
|
|
36
|
-
counter: credential.counter,
|
|
37
|
-
backedUp: credential.backedUp,
|
|
38
|
-
transports: credential.transports
|
|
39
|
-
});
|
|
40
|
-
await setUserSession(event, { user: mapUserToSession(dbUser) });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { H3Event } from 'h3';
|
|
2
|
-
type OAuthProfile = Record<string, unknown>;
|
|
3
|
-
/**
|
|
4
|
-
* Shared find-or-create logic used by the "simple" nuxt-auth-utils OAuth
|
|
5
|
-
* routes registered through `settings.oauth` in the module config.
|
|
6
|
-
*/
|
|
7
|
-
export declare function handleOAuthUser(event: H3Event, provider: string, profile: OAuthProfile): Promise<any>;
|
|
8
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
export async function handleOAuthUser(event, provider, profile) {
|
|
3
|
-
const email = profile.email;
|
|
4
|
-
if (!email) {
|
|
5
|
-
throw createError({ statusCode: 400, statusMessage: `No email returned from the ${provider} OAuth provider.` });
|
|
6
|
-
}
|
|
7
|
-
let dbUser = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.email, email) });
|
|
8
|
-
if (!dbUser) {
|
|
9
|
-
const [created] = await db.insert(schema.users).values({
|
|
10
|
-
name: profile.name ?? profile.login ?? email,
|
|
11
|
-
email,
|
|
12
|
-
avatar: profile.avatar_url ?? profile.picture
|
|
13
|
-
}).returning();
|
|
14
|
-
dbUser = created;
|
|
15
|
-
}
|
|
16
|
-
await setUserSession(event, { user: mapUserToSession(dbUser) });
|
|
17
|
-
return sendRedirect(event, "/");
|
|
18
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { EmailNotification } from '@frigear-nu/notify/types';
|
|
2
|
-
export type PasswordResetEmailPayload = {
|
|
3
|
-
to: string;
|
|
4
|
-
resetUrl: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Generates a URL-safe, unguessable code for a password reset request. Uses the Web Crypto API
|
|
8
|
-
* (available in all Nitro presets) rather than pulling in a dependency just for this.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createPasswordResetCode(): string;
|
|
11
|
-
/**
|
|
12
|
-
* Builds the `EmailNotification` for a password reset request. Kept separate from dispatch so it
|
|
13
|
-
* stays trivial to test, and so future notifications follow the same "build, then dispatch"
|
|
14
|
-
* shape without needing their own module option.
|
|
15
|
-
*/
|
|
16
|
-
export declare function buildPasswordResetNotification({ to, resetUrl }: PasswordResetEmailPayload): EmailNotification;
|
|
17
|
-
/**
|
|
18
|
-
* Dispatches the "reset your password" email through whichever email driver the app has
|
|
19
|
-
* configured on `@frigear-nu/notify` (defaults to logging it). `dispatchEmailNotification` is
|
|
20
|
-
* auto-imported once `@frigear-nu/notify` is installed - it's a `moduleDependency` of this module.
|
|
21
|
-
*/
|
|
22
|
-
export declare function dispatchPasswordResetEmail(payload: PasswordResetEmailPayload): Promise<void>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function createPasswordResetCode() {
|
|
2
|
-
return crypto.randomUUID().replace(/-/g, "");
|
|
3
|
-
}
|
|
4
|
-
export function buildPasswordResetNotification({ to, resetUrl }) {
|
|
5
|
-
return {
|
|
6
|
-
to,
|
|
7
|
-
subject: "Reset your password",
|
|
8
|
-
body: `<p>Click the link below to reset your password:</p><p><a href="${resetUrl}">${resetUrl}</a></p>`,
|
|
9
|
-
text: `Reset your password: ${resetUrl}`
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export async function dispatchPasswordResetEmail(payload) {
|
|
13
|
-
await dispatchEmailNotification(buildPasswordResetNotification(payload));
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type SafeUser = Record<string, unknown>;
|
|
2
|
-
/**
|
|
3
|
-
* Strips the password hash from an already-loaded DB user record and passes it through the
|
|
4
|
-
* (possibly user-overridden) session mapper. Called once, at login/registration time, with the
|
|
5
|
-
* user record the caller already fetched or created - the enriched result is stored directly in
|
|
6
|
-
* the session, so we don't need to re-query the database on every subsequent session read.
|
|
7
|
-
*/
|
|
8
|
-
export declare function mapUserToSession(dbUser: SafeUser & {
|
|
9
|
-
password?: string | null;
|
|
10
|
-
}): any;
|
|
11
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/runtime/server/{routes/auth/forgot-password.post.d.ts → mcp/tools/get-my-profile.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/runtime/server/routes/{auth/webauthn/authenticate.post.d.ts → admin/user.patch.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/runtime/server/routes/{auth/webauthn/register.post.d.ts → me/change-email.post.d.ts}
RENAMED
|
File without changes
|