mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 10:16:32 +02:00
🐛 Fix issue where verification links would automatically get consumed by link checkers (#1060)
* 🧹 Remove legacy code * ♻️ Handle HEAD requests to auth endpoint Avoid link checkers from accidentally consuming verification links and preventing users from logging in
This commit is contained in:
parent
e8911583df
commit
113239c546
2 changed files with 10 additions and 35 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
import { AuthApiRoute } from "@/utils/auth";
|
import { AuthApiRoute } from "@/utils/auth";
|
||||||
|
|
||||||
export default AuthApiRoute;
|
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
if (req.method === "HEAD") {
|
||||||
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
return AuthApiRoute(req, res);
|
||||||
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@ import { RegistrationTokenPayload } from "@rallly/backend";
|
||||||
import { decryptToken } from "@rallly/backend/session";
|
import { decryptToken } from "@rallly/backend/session";
|
||||||
import { generateOtp, randomid } from "@rallly/backend/utils/nanoid";
|
import { generateOtp, randomid } from "@rallly/backend/utils/nanoid";
|
||||||
import { prisma } from "@rallly/database";
|
import { prisma } from "@rallly/database";
|
||||||
import cookie from "cookie";
|
|
||||||
import { IronSession, unsealData } from "iron-session";
|
|
||||||
import {
|
import {
|
||||||
GetServerSidePropsContext,
|
GetServerSidePropsContext,
|
||||||
NextApiRequest,
|
NextApiRequest,
|
||||||
NextApiResponse,
|
NextApiResponse,
|
||||||
} from "next";
|
} from "next";
|
||||||
import { NextAuthOptions, RequestInternal } from "next-auth";
|
import { NextAuthOptions } from "next-auth";
|
||||||
import NextAuth, {
|
import NextAuth, {
|
||||||
getServerSession as getServerSessionWithOptions,
|
getServerSession as getServerSessionWithOptions,
|
||||||
} from "next-auth/next";
|
} from "next-auth/next";
|
||||||
|
@ -318,34 +316,3 @@ export const isEmailBlocked = (email: string) => {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const legacySessionConfig = {
|
|
||||||
password: process.env.SECRET_PASSWORD ?? "",
|
|
||||||
cookieName: "rallly-session",
|
|
||||||
cookieOptions: {
|
|
||||||
secure: process.env.NEXT_PUBLIC_BASE_URL?.startsWith("https://") ?? false,
|
|
||||||
},
|
|
||||||
ttl: 60 * 60 * 24 * 30, // 30 days
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getUserFromLegacySession = async (
|
|
||||||
req: Pick<RequestInternal, "headers">,
|
|
||||||
) => {
|
|
||||||
const parsedCookie = cookie.parse(req.headers?.cookie);
|
|
||||||
if (parsedCookie[legacySessionConfig.cookieName]) {
|
|
||||||
try {
|
|
||||||
const session = await unsealData<IronSession>(
|
|
||||||
parsedCookie[legacySessionConfig.cookieName],
|
|
||||||
{
|
|
||||||
password: process.env.SECRET_PASSWORD,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (session.user) {
|
|
||||||
return session.user;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue