Skip to content

Commit

Permalink
verify email change
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin committed Feb 10, 2024
1 parent 31ac87f commit c2f4fd2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/app/routes/_base.verify-email-change.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Text } from "@radix-ui/themes";
import type { LoaderFunctionArgs } from "@remix-run/node";

import { prisma } from "../../shared/prisma.server";
import { CenterLayout } from "../components/center-layout";
import { assertSession } from "../session.server";

export const loader = async ({ request }: LoaderFunctionArgs) => {
const session = await assertSession(request);

const url = new URL(request.url);
const token = url.searchParams.get("token");

if (!token) {
throw new Response("token missing", { status: 400 });
}

const emailChange = await prisma.userEmailChange.findUnique({
where: {
token,
userId: session.user.id,
},
select: {
id: true,
email: true,
},
});

if (!emailChange) {
throw new Response("invalid token", { status: 400 });
}

await prisma.userEmailChange.delete({
where: { id: emailChange.id },
});

await prisma.user.update({
where: {
id: session.user.id,
},
data: {
email: emailChange.email,
},
});

return null;
};

export default () => (
<CenterLayout>
<Text>Eメールアドレスを変更しました</Text>
</CenterLayout>
);

export const ErrorBoundary = () => {
return (
<CenterLayout>
<Text color="red">エラーが発生しました</Text>
</CenterLayout>
);
};

0 comments on commit c2f4fd2

Please sign in to comment.