This commit is contained in:
parent
975fa1a7e2
commit
5ca0e9ad80
|
|
@ -19,28 +19,13 @@ export const metadata: Metadata = {
|
||||||
title: "Login"
|
title: "Login"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LoginPageProps {
|
|
||||||
searchParams: { message: string; email?: string };
|
|
||||||
params: { locale: string };
|
|
||||||
req: NextPageContext['req']; // 用 NextPageContext 的 req 类型来定义
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// export default async function Login({
|
|
||||||
// searchParams,
|
|
||||||
// params: { locale },
|
|
||||||
// req, // 请求对象
|
|
||||||
// }: {
|
|
||||||
// searchParams: { message: string; email?: string };
|
|
||||||
// params: { locale: string };
|
|
||||||
// req: Request; // 获取请求对象
|
|
||||||
// }) {
|
|
||||||
|
|
||||||
export default async function Login({
|
export default async function Login({
|
||||||
searchParams,
|
searchParams,
|
||||||
params: { locale },
|
params: { locale },
|
||||||
req, // 请求对象
|
}: {
|
||||||
}: LoginPageProps) {
|
searchParams: { message: string; email?: string };
|
||||||
|
params: { locale: string };
|
||||||
|
}) {
|
||||||
const cookieStore = cookies()
|
const cookieStore = cookies()
|
||||||
|
|
||||||
const localeString = locale;
|
const localeString = locale;
|
||||||
|
|
@ -60,31 +45,31 @@ export default async function Login({
|
||||||
.eq("is_home", true)
|
.eq("is_home", true)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
|
|
||||||
// Define the clearCookies function for server-side execution
|
// // Define the clearCookies function for server-side execution
|
||||||
const clearCookies = async () => {
|
// const clearCookies = async () => {
|
||||||
// From request headers or environment variables
|
// // From request headers or environment variables
|
||||||
let hosturl: string | undefined;
|
// let hosturl: string | undefined;
|
||||||
|
|
||||||
// Option 1: Get host from request headers (useful for dynamic requests)
|
// // Option 1: Get host from request headers (useful for dynamic requests)
|
||||||
const hostHeader = req.headers.get('host');
|
// const hostHeader = req.headers.get('host');
|
||||||
if (hostHeader) {
|
// if (hostHeader) {
|
||||||
hosturl = `http://${hostHeader}`; // Construct full URL
|
// hosturl = `http://${hostHeader}`; // Construct full URL
|
||||||
} else {
|
// } else {
|
||||||
// Option 2: Use environment variable as fallback
|
// // Option 2: Use environment variable as fallback
|
||||||
hosturl = process.env.SUPABASE_URL; // Ensure you have this set up in your environment variables
|
// hosturl = process.env.SUPABASE_URL; // Ensure you have this set up in your environment variables
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (hosturl) {
|
// if (hosturl) {
|
||||||
await fetch(`${hosturl}/api/clearcookies`, {
|
// await fetch(`${hosturl}/api/clearcookies`, {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
});
|
// });
|
||||||
} else {
|
// } else {
|
||||||
console.error("Host URL is not available");
|
// console.error("Host URL is not available");
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
if (!homeWorkspace) {
|
if (!homeWorkspace) {
|
||||||
await clearCookies(); // Clear cookies if home workspace is not found
|
//await clearCookies(); // Clear cookies if home workspace is not found
|
||||||
return redirect(`/${localeString}/login?message=sessionExpired`);
|
return redirect(`/${localeString}/login?message=sessionExpired`);
|
||||||
}
|
}
|
||||||
return redirect(`/${localeString}/${homeWorkspace.id}/chat`);
|
return redirect(`/${localeString}/${homeWorkspace.id}/chat`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue