https://supertokens.com/ logo
#general
Title
# general
b

beagle

04/29/2022, 8:43 AM
Hi, we have successfully implemented passwordless authentication in our application. Now we would like to disable the registration of new users, so that only the login works and not the registration. We have implemented the following in the Nestjs backend:
Copy code
Passwordless.init({
          override: {
            apis: (originalImplementation) => {
              return {
                ...originalImplementation,
                createCodePOST: async function (input) {
                  const existingUser = await Passwordless.getUserByEmail({
                    email: (input as { email: string }).email,
                  });
                  if (!!existingUser) {
                    throw new ForbiddenException(
                      'Creating a new user is not allowed'
                    );
                  }
                  return await originalImplementation.createCodePOST(input);
                },
              };
            },
          },
          ...
Now this works fine, but in the frontend I don't see the error message
Creating a new user is not allowed
but
Something went wrong. Please try again
. Now 2 questions: 1. is this the right way to deactivate the registration of new users in the passwordless authentication? 2. how can I override the default error message in the FE? Thanks a lot 🙂
r

rp

04/29/2022, 8:44 AM
Hey!
Yes. This is the right way.
You can return a {status: “GENERAL_ERROR”, message: “…”} instead of throwing an error
And then the FE will display that message
b

beagle

04/29/2022, 8:46 AM
aaah ok thx a lot 😄
4 Views