๋ฌธ์ ์
Error: NEXT_REDIRECT ๋ฐ์ํ๋ฉด์ ๋ก๊ทธ์ธ ์ ์๋ ๋ฆฌ๋ค์ด๋ ํธ ๋์ง์์ผ๋ฉฐ ์๋ก๊ณ ์นจ์ ์ด๋๋จ
๋ฌธ์ ์ ์์ค์ฝ๋์์๋ return์ผ๋ก ์ฒ๋ฆฌํ๊ณ ์๋ค. signIn ํจ์๊ฐ ์คํ๋๊ณ ๋ฆฌ๋ค์ด๋ ์ ์ฒ๋ฆฌ๊ฐ ๋๋๋ฐ return์ด ์คํ๋์ด ๋ฌด๋ฐ์์ธ ์ํฉ์ด๋ค
"use server";
import { signIn } from "@/auth";
import { DEFAULT_LOGIN_REDIRECT } from "@/route";
import { z } from "zod";
import { AuthError } from "next-auth";
import { SignInSchema } from "@/schemas";
export const login = async (values: z.infer<typeof SignInSchema>) => {
const validatedFields = SignInSchema.safeParse(values);
if (!validatedFields.success) {
return {
result: false,
message: { title: "๋ก๊ทธ์ธ ์คํจ", description: "๋ถ์ ์ ํ ์
๋ ฅ๊ฐ" },
};
}
const { email, password } = validatedFields.data;
try {
await signIn("credentials", {
email,
password,
redirectTo: DEFAULT_LOGIN_REDIRECT,
});
return {
result: true,
message: { title: "๋ก๊ทธ์ธ ์ฑ๊ณต", description: "ํ์ํฉ๋๋ค." },
};
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
case "CredentialsSignin":
return {
result: false,
message: { title: "๋ก๊ทธ์ธ ์คํจ", description: "๊ณ์ ์ ๋ณด ๋ถ์ผ์น" },
};
default:
return {
result: false,
message: {
title: "๋ก๊ทธ์ธ ์คํจ",
description: "์๋ฌ๊ฐ ๋ฐ์ ํ์ต๋๋ค",
},
};
}
}
// ๋ฌธ์ ์ ์์ค์ฝ๋ ๋ถ๋ถ
return {
result: false,
message: {
title: "๋ก๊ทธ์ธ ์คํจ",
description: "์๋ฒ ์๋ฌ๊ฐ ๋ฐ์ ํ์ต๋๋ค",
},
};
}
};
ํด๊ฒฐ๋ฐฉ๋ฒ
๋ก๊ทธ์ธ ์๋ฒ ์ปดํฌ๋ํธ์์ ๋ณ๋์ return ์ฒ๋ฆฌํ์ง ์๊ธฐ
"use server";
import { signIn } from "@/auth";
import { DEFAULT_LOGIN_REDIRECT } from "@/route";
import { z } from "zod";
import { AuthError } from "next-auth";
import { SignInSchema } from "@/schemas";
export const login = async (values: z.infer<typeof SignInSchema>) => {
const validatedFields = SignInSchema.safeParse(values);
if (!validatedFields.success) {
return {
result: false,
message: { title: "๋ก๊ทธ์ธ ์คํจ", description: "๋ถ์ ์ ํ ์
๋ ฅ๊ฐ" },
};
}
const { email, password } = validatedFields.data;
try {
await signIn("credentials", {
email,
password,
redirectTo: DEFAULT_LOGIN_REDIRECT,
});
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
case "CredentialsSignin":
return {
result: false,
message: { title: "๋ก๊ทธ์ธ ์คํจ", description: "๊ณ์ ์ ๋ณด ๋ถ์ผ์น" },
};
default:
return {
result: false,
message: {
title: "๋ก๊ทธ์ธ ์คํจ",
description: "์๋ฌ๊ฐ ๋ฐ์ ํ์ต๋๋ค",
},
};
}
}
throw error;
}
};
'๐ค์ ๋ณด๋ณด์ > ๐ 1๋ถ์ง์' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ ๋ณด] Ubuntu Server์์ Chrome Selenium ์ฌ์ฉํ๊ธฐ (0) | 2024.06.19 |
---|---|
[์ ๋ณด] ๋ฉ์ผ์๋ฒ ์ฝ๊ฒ์ค์นํ๊ธฐ docker mailserver (0) | 2024.06.17 |
[AI] Meta Llama 3 ์ ์ฉ ํ๊ธฐ (0) | 2024.06.16 |
[Auth.js] CloudFlare AUTH_TRUST_HOST ์ค์ (0) | 2024.06.10 |
[์ ํจ์ค] ๊ฐ์๊ธฐ Error cloning remote repo 'origin' ๋ฌธ์ ํด๊ฒฐ๋ฐฉ๋ฒ (0) | 2024.06.07 |