Error messages in deployment environment.
Answered
Jersey Wooly posted this in #help-forum
Jersey WoolyOP
export async function CreateUser(data: UserForm) {
const session = await getServerSession(options);
if (!session || session.user.role !== 'ADMIN') {
throw new Error('Only admins can create users');
}
// console.log(data);
const validation = signupFormSchema.safeParse(data);
if (!validation.success) {
throw new Error('Registration invalid');
}
const existingUser = await prisma.user.findUnique({
where: { email: data.email },
});
if (existingUser) {
throw new Error('User with that email already exists');
}
}This is part of my server action. However in my deployment setting, for e.g. when I enter the same email as an existing user. I get
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error. instead of my 'User with that email already exists' message. How do I show my message instead?Answered by not-milo.tsx
You can't. In production error messages are intentionally obfuscated so that you don't accidentally leak sensitive information.
If you want to display a useful error message to your users either use an error boundary or add some search parameters to the url that render a toast with your message in it.
If you want to display a useful error message to your users either use an error boundary or add some search parameters to the url that render a toast with your message in it.
2 Replies
You can't. In production error messages are intentionally obfuscated so that you don't accidentally leak sensitive information.
If you want to display a useful error message to your users either use an error boundary or add some search parameters to the url that render a toast with your message in it.
If you want to display a useful error message to your users either use an error boundary or add some search parameters to the url that render a toast with your message in it.
Answer
For the first option see: https://nextjs.org/docs/app/api-reference/file-conventions/error
And for the second you can create a client component that uses the
And for the second you can create a client component that uses the
useSearchParams hook and renders a toast (maybe with Sonner) if for example there is a toastMessage parameter.