Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ public/sitemap.xml
/blob-report/
/playwright/.cache/
/playwright/.auth/

# TypeScript build info
tsconfig.tsbuildinfo

# MCP config (local tool settings)
.mcp.json
12 changes: 11 additions & 1 deletion components/Forms/UpdateProfileForm/UpdateProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ function UpdateProfileForm({
}
}

await updateUser(values);
try {
await updateUser(values);
} catch (error) {
const axiosError = error as AxiosError;
if (axiosError.response?.status === 404) {
// Record no longer exists — cookie was cleared by the API, redirect to re-register
push('/join');
return;
}
throw error;
}
};

const goToProfile = async () => {
Expand Down
16 changes: 12 additions & 4 deletions pages/api/registration/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

const email = req.cookies?.opCodeApplicantEmail;

// The cookie is cleared on the final successful step (when all fields are filled).
// Additional PATCH requests can still arrive after that (e.g. user double-clicking),
// so we need to bail out early rather than querying Airtable with an undefined email.
if (!email) {
return res.status(401).json({ message: 'Missing registration cookie' });
}

try {
// Search for a record with the relevant email
const records = await base(AIR_TABLE_TABLE_NAME)
Expand Down Expand Up @@ -96,10 +103,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(200).json({ message: 'Success' });
}

// No record found, add a new row to the table
return res
.writeHead(404, { Location: '/' })
.json({ message: `No record found for this email (${email})` });
// No record found — clear the stale cookie so the page guard redirects to /
res.setHeader('Set-Cookie', [
`opCodeApplicantEmail=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`,
]);
return res.status(404).json({ message: `No record found for this email (${email})` });
} catch (error) {
console.error('Error with /api/registration/update PATCH request:', error);
return res.status(500).json({ message: 'Server Error' });
Expand Down
Loading