mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Merge pull request #197 from Hestia-Homes/main
db migration + magic links fix
This commit is contained in:
commit
568e94c87c
8 changed files with 5762 additions and 8 deletions
BIN
public/domna-email-logo.png
Normal file
BIN
public/domna-email-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
|
|
@ -146,8 +146,8 @@ export const AuthOptions: NextAuthOptions = {
|
|||
.where(
|
||||
and(
|
||||
eq(accounts.userId, dbUser.id),
|
||||
eq(accounts.provider, account.provider)
|
||||
)
|
||||
eq(accounts.provider, account.provider),
|
||||
),
|
||||
);
|
||||
|
||||
const emailVerified =
|
||||
|
|
@ -157,7 +157,7 @@ export const AuthOptions: NextAuthOptions = {
|
|||
// This handles the case where we had not set up accounts but
|
||||
// signed up users with oauth
|
||||
console.log(
|
||||
`Linking ${account.provider} account for user ${normalisedEmail}`
|
||||
`Linking ${account.provider} account for user ${normalisedEmail}`,
|
||||
);
|
||||
|
||||
await db
|
||||
|
|
|
|||
4
src/app/db/migrations/0155_calm_hydra.sql
Normal file
4
src/app/db/migrations/0155_calm_hydra.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE "postcode_search" ADD COLUMN "last_updated_at" timestamp;--> statement-breakpoint
|
||||
UPDATE "postcode_search" SET "last_updated_at" = "created_at";--> statement-breakpoint
|
||||
ALTER TABLE "postcode_search" ALTER COLUMN "last_updated_at" SET DEFAULT now();--> statement-breakpoint
|
||||
ALTER TABLE "postcode_search" ALTER COLUMN "last_updated_at" SET NOT NULL;
|
||||
5696
src/app/db/migrations/meta/0155_snapshot.json
Normal file
5696
src/app/db/migrations/meta/0155_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1086,6 +1086,13 @@
|
|||
"when": 1772194536121,
|
||||
"tag": "0154_workable_stingray",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 155,
|
||||
"version": "7",
|
||||
"when": 1772637615885,
|
||||
"tag": "0155_calm_hydra",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -32,4 +32,5 @@ export const postcodeSearch = pgTable("postcode_search", {
|
|||
|
||||
// Timestamp for when the entry was first created
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
lastUpdatedAt: timestamp("last_updated_at").defaultNow().notNull(),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,21 @@ export async function MagicLinksEmail({
|
|||
url: string;
|
||||
provider: { server: any; from: string };
|
||||
}) {
|
||||
const { host } = new URL(url);
|
||||
const parsed = new URL(url);
|
||||
const host = parsed.host;
|
||||
|
||||
const baseUrl = parsed.origin;
|
||||
const logoUrl = `${baseUrl}/domna-email-logo.png`;
|
||||
|
||||
const token = parsed.searchParams.get("token");
|
||||
const email = parsed.searchParams.get("email");
|
||||
|
||||
if (!token || !email) {
|
||||
throw new Error("Magic link token or email missing");
|
||||
}
|
||||
|
||||
// Create a clean login link instead of the NextAuth callback
|
||||
const loginUrl = `${parsed.origin}/login/${token}/${encodeURIComponent(email)}`;
|
||||
|
||||
const transport = createTransport(provider.server);
|
||||
|
||||
|
|
@ -25,9 +39,20 @@ export async function MagicLinksEmail({
|
|||
const result = await transport.sendMail({
|
||||
to: identifier,
|
||||
from: provider.from,
|
||||
subject: "Your secure Ara sign-in link",
|
||||
text: plainText({ url, host }),
|
||||
html: domnaHtml({ url, host, brandColor, accentColor, brown, background }),
|
||||
subject: "Sign in to Ara",
|
||||
text: plainText({ url: loginUrl, host }),
|
||||
html: domnaHtml({
|
||||
url: loginUrl,
|
||||
logoUrl,
|
||||
host,
|
||||
brandColor,
|
||||
accentColor,
|
||||
brown,
|
||||
background,
|
||||
}),
|
||||
headers: {
|
||||
"List-Unsubscribe": `<mailto:${provider.from}>`,
|
||||
},
|
||||
});
|
||||
|
||||
const failed = result.rejected.filter(Boolean);
|
||||
|
|
@ -38,6 +63,7 @@ export async function MagicLinksEmail({
|
|||
|
||||
function domnaHtml({
|
||||
url,
|
||||
logoUrl,
|
||||
host,
|
||||
brandColor,
|
||||
accentColor,
|
||||
|
|
@ -45,6 +71,7 @@ function domnaHtml({
|
|||
background,
|
||||
}: {
|
||||
url: string;
|
||||
logoUrl: string;
|
||||
host: string;
|
||||
brandColor: string;
|
||||
accentColor: string;
|
||||
|
|
@ -60,7 +87,7 @@ function domnaHtml({
|
|||
<tr>
|
||||
<td align="center" style="background: linear-gradient(90deg, ${brandColor}, ${accentColor}); padding: 12px 8px;">
|
||||
<img
|
||||
src="https://145275138.fs1.hubspotusercontent-eu1.net/hubfs/145275138/base_logo_transparent_background.png"
|
||||
src="${logoUrl}"
|
||||
alt="Domna Logo"
|
||||
width="120"
|
||||
height="auto"
|
||||
|
|
|
|||
19
src/app/login/[token]/[email]/page.tsx
Normal file
19
src/app/login/[token]/[email]/page.tsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function LoginPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ token: string; email: string }>;
|
||||
}) {
|
||||
const { token, email } = await params;
|
||||
|
||||
if (!token || !email) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
const decodedEmail = decodeURIComponent(email);
|
||||
|
||||
redirect(
|
||||
`/api/auth/callback/email?token=${token}&email=${encodeURIComponent(decodedEmail)}`,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue