Add password reset flow
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
function assert(condition: unknown, message: string) {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
export function runTests() {
|
||||
const projectRoot = process.cwd();
|
||||
const loginClientPath = path.join(
|
||||
projectRoot,
|
||||
"components",
|
||||
"auth",
|
||||
"LoginClient.tsx",
|
||||
);
|
||||
const resetPagePath = path.join(
|
||||
projectRoot,
|
||||
"app",
|
||||
"auth",
|
||||
"reset-password",
|
||||
"page.tsx",
|
||||
);
|
||||
const resetClientPath = path.join(
|
||||
projectRoot,
|
||||
"components",
|
||||
"auth",
|
||||
"ResetPasswordClient.tsx",
|
||||
);
|
||||
|
||||
const loginClientSource = fs.readFileSync(loginClientPath, "utf8");
|
||||
|
||||
assert(
|
||||
loginClientSource.includes("/auth/reset-password") &&
|
||||
loginClientSource.indexOf("resetPasswordForEmail") <
|
||||
loginClientSource.indexOf("/auth/reset-password"),
|
||||
"forgot-password emails must land on a password reset page after auth callback",
|
||||
);
|
||||
assert(
|
||||
fs.existsSync(resetPagePath),
|
||||
"password reset page must exist at app/auth/reset-password/page.tsx",
|
||||
);
|
||||
assert(
|
||||
fs.existsSync(resetClientPath),
|
||||
"password reset page must use a dedicated client component",
|
||||
);
|
||||
|
||||
const resetClientSource = fs.readFileSync(resetClientPath, "utf8");
|
||||
assert(
|
||||
resetClientSource.includes("supabase.auth.updateUser") &&
|
||||
resetClientSource.includes("password"),
|
||||
"password reset client must update the authenticated user's password",
|
||||
);
|
||||
assert(
|
||||
resetClientSource.includes("getSession") &&
|
||||
resetClientSource.includes("expired"),
|
||||
"password reset client must detect an expired or invalid recovery session",
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user