return error as object from server actions

This commit is contained in:
peintnermax
2024-09-16 14:41:38 +02:00
parent 7126f86c33
commit 4077353048
3 changed files with 12 additions and 10 deletions

View File

@@ -33,9 +33,6 @@ const secureHeaders = [
const nextConfig = { const nextConfig = {
reactStrictMode: true, // Recommended for the `pages` directory, default in `app`. reactStrictMode: true, // Recommended for the `pages` directory, default in `app`.
swcMinify: true, swcMinify: true,
experimental: {
serverComponentsErrorOverride: true,
},
images: { images: {
remotePatterns: [ remotePatterns: [
{ {

View File

@@ -79,7 +79,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
); );
if (!session.factors?.user?.id) { if (!session.factors?.user?.id) {
throw Error("Could not create session for user"); return { error: "Could not create session for user" };
} }
const methods = await listAuthenticationMethodTypes( const methods = await listAuthenticationMethodTypes(
@@ -87,9 +87,10 @@ export async function sendLoginname(command: SendLoginnameCommand) {
); );
if (!methods.authMethodTypes || !methods.authMethodTypes.length) { if (!methods.authMethodTypes || !methods.authMethodTypes.length) {
throw Error( return {
"User has no available authentication methods. Contact your administrator to setup authentication for the requested user.", error:
); "User has no available authentication methods. Contact your administrator to setup authentication for the requested user.",
};
} }
if (methods.authMethodTypes.length == 1) { if (methods.authMethodTypes.length == 1) {
@@ -175,7 +176,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
// TODO: do we need to handle login hints for IDPs here? // TODO: do we need to handle login hints for IDPs here?
await redirectUserToSingleIDPIfAvailable(); await redirectUserToSingleIDPIfAvailable();
throw Error("Could not find user"); return { error: "Could not find user" };
} else if ( } else if (
loginSettings?.allowRegister && loginSettings?.allowRegister &&
loginSettings?.allowUsernamePassword loginSettings?.allowUsernamePassword
@@ -232,5 +233,5 @@ export async function sendLoginname(command: SendLoginnameCommand) {
return redirect("/password?" + new URLSearchParams(paramsPasswordDefault)); return redirect("/password?" + new URLSearchParams(paramsPasswordDefault));
} }
throw Error("Could not find user"); return { error: "Could not find user" };
} }

View File

@@ -51,9 +51,13 @@ export default function UsernameForm({
organization, organization,
authRequestId, authRequestId,
}).catch((error: Error) => { }).catch((error: Error) => {
setError(error.message ?? "An internal error occurred"); setError("An internal error occurred");
}); });
if (res?.error) {
setError(res.error);
}
setLoading(false); setLoading(false);
return res; return res;