Next.js Discord

Discord Forum

Users not appearing into Clerk's Database after Signing-up

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
It looks like the sign-up process is completed because the user does get redirected back to my log-in page after signing up, however for some reason it looks like the user is not inserted into the user database after signing up.

I did try to look-up this issue but I wasn't able to find a solution yet. I would like to know what could cause this issue and how can I fix it.

I've attached some screenshots as well and I can provide more details if required.
Answered by Sun bear
How I solved it: With the help of Chat Gippitty and the example for the Sign-up process in here: https://clerk.com/docs/custom-flows/email-password

Thank you very much for your help as well Adam, and I hope you're having an awesome day!
View full answer

93 Replies

Asiatic Lion
Hi, @Sun bear I'd like to tell you take a look at the status code of signup api request.
@Asiatic Lion Hi, <@998405690718703696> I'd like to tell you take a look at the status code of signup api request.
Sun bearOP
Hey Witty. Thanks for the reply, had no idea that's a thing. Would i find that in the console logs or somewhere else ? Or do I have to manually log it ?
Asiatic Lion
you'd better to check the both.
In the console logs and you can log it on the backend part right below code for creating new user.
@Asiatic Lion you'd better to check the both. In the console logs and you can log it on the backend part right below code for creating new user.
Sun bearOP
Thank you, it did not appear but I added some console logs with gpt and I think I got it, but have no idea what it means. Can you have a look and let me know if you know what that code means ?
Asiatic Lion
Signup attempt status: missing_requirements
is this on frontend code? would you provide me the code for this log?
@Asiatic Lion is this on frontend code? would you provide me the code for this log?
Sun bearOP
const handleFormSubmit = async () => {
    console.log("Form Submitted", formData);

    // Check if signUp is defined
    if (!signUp) {
        console.error("signUp function is not available.");
        // Optionally, handle this error case, e.g., by showing a user-friendly message
        return;
    }

    try {
        const signUpResult = await signUp.create({
            emailAddress: formData.accountDetails.email,
            password: formData.accountDetails.password,
            // Optionally add firstName, lastName if Clerk supports it in your setup
        });

        console.log("SignUp attempt status:", signUpResult.status); // Log Clerk sign-up status

        // On successful sign-up with Clerk, proceed with submitting additional data
        const response = await fetch(`/${lang}/signup/submit`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(formData),
        });

        console.log('HTTP Status Code from signup/submit:', response.status); // Log the HTTP status code

        let data = await response.json();

        if (!response.ok) {
            console.error(`Error submitting form data: ${response.status} ${response.statusText}`, 'Error details:', data);
            return; // Handle error, e.g., show error message
        }

        console.log('Data submitted successfully:', data);
        router.push(`/${lang}/login`);
    } catch (error) {
        console.error('Error during sign-up or data submission:', error);
        // Handle error, e.g., show error message
    }
};

I think this is the code responsible for it.
Asiatic Lion
when execute signUp.create, required fields are missing.
try to log requiredFields now.
or requiredFields...
@Asiatic Lion when execute signUp.create, required fields are missing.
Sun bearOP
I think it worked, we have more information in the logs now!
But it doesn't seem to say what fields it wants. Don't we already provide the 2 fields it complains about ?
Asiatic Lion
you only logged missing fields?
really weird.
Sun bearOP
It added these logs:
        console.log("SignUp attempt status:", signUpResult.status); // Log Clerk sign-up status
        if (signUpResult.status === 'missing_requirements') {
            console.log("Missing required fields:", signUpResult.requiredFields);
            // Optionally, inform the user which fields are required but missing
        }

        // Check if sign-up is not complete due to missing requirements
        if (signUpResult.status !== 'complete') {
            console.error("Sign-up incomplete, missing requirements:", signUpResult.requiredFields);
            return; // Exit the function if sign-up is not complete
        }
I have found something in regards with the error in the meantime https://clerk.com/docs/references/javascript/sign-up/sign-up
For the missing_requirements
Sun bearOP
I'm going to try this suggestion
Asiatic Lion
I think, email_address is unverified ones.
try to log unverifiedFields
@Asiatic Lion I think, email_address is unverified ones.
Sun bearOP
Yeah, dead end here.
Asiatic Lion
emailAddress which you did before, is right.
@Asiatic Lion try to log unverifiedFields
Sun bearOP
I'm going to need your help with logging those, because it looks like GPT is not familiar with logging those. What do I need to add in my code ?
const handleFormSubmit = async () => {
    console.log("Form Submitted", formData);

    if (!signUp) {
        console.error("signUp function is not available.");
        return;
    }

    try {
        const signUpResult = await signUp.create({
            emailAddress: formData.accountDetails.email,
            password: formData.accountDetails.password,
        });

        console.log("SignUp attempt status:", signUpResult.status);
        if (signUpResult.status === 'missing_requirements') {
            console.log("Missing required fields:", signUpResult.requiredFields);
        }

        if (signUpResult.status !== 'complete') {
            console.error("Sign-up incomplete, missing requirements:", signUpResult.requiredFields);
            return;
        }

        const response = await fetch(`/${lang}/signup/submit`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(formData),
        });

        console.log('HTTP Status Code from signup/submit:', response.status);

        let data = await response.json();

        if (!response.ok) {
            console.error(`Error submitting form data: ${response.status} ${response.statusText}`, 'Error details:', data);
            return;
        }

        console.log('Data submitted successfully:', data);
        router.push(`/${lang}/login`);
    } catch (error) {
        console.error('Error during sign-up or data submission:', error);
      
    }
};
Asiatic Lion
const handleFormSubmit = async () => {
    console.log("Form Submitted", formData);

    if (!signUp) {
        console.error("signUp function is not available.");
        return;
    }

    try {
        const signUpResult = await signUp.create({
            emailAddress: formData.accountDetails.email,
            password: formData.accountDetails.password,
        });

        console.log("SignUp attempt status:", signUpResult.status);
        console.log("Required fields: signUpResult.requiredFields);
        console.log("unverified fields: signUpResult.unverifiedFields);
        console.log("missing fields: signUpResult.missingFields);

        const response = await fetch(`/${lang}/signup/submit`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(formData),
        });

        console.log('HTTP Status Code from signup/submit:', response.status);

        let data = await response.json();

        if (!response.ok) {
            console.error(`Error submitting form data: ${response.status} ${response.statusText}`, 'Error details:', data);
            return;
        }

        console.log('Data submitted successfully:', data);
        router.push(`/${lang}/login`);
    } catch (error) {
        console.error('Error during sign-up or data submission:', error);
      
    }
};
Asiatic Lion
Whoops. my mistake. change to this again
console.log("SignUp attempt status:", signUpResult.status);
        console.log("Required fields:",  signUpResult.requiredFields);
        console.log("unverified fields: ", signUpResult.unverifiedFields);
@Asiatic Lion Whoops. my mistake. change to this again console.log("SignUp attempt status:", signUpResult.status); console.log("Required fields:", signUpResult.requiredFields); console.log("unverified fields: ", signUpResult.unverifiedFields);
Sun bearOP
By the way, VSCode told me to do it like this in terms of paranthesis and whatnot (otherwise it gave errors)
Asiatic Lion
so change to this.
console.log("SignUp attempt status:", signUpResult.status);
console.log("Required fields:", signUpResult.requiredFields);
console.log("unverified fields: ", signUpResult.unverifiedFields);
Asiatic Lion
Take a look at this. you should verify emailAddress before create signup.
it's not that verification email...
Hold on
I am already verifying the e-mail
What does "unverified" stand for in this situation ?
Asiatic Lion
ahh~~ so if you click signup button, what happens?
Sun bearOP
It just redirects me back to the log-in page
Asiatic Lion
you get verification code or link?
Sun bearOP
Nope
Because the user doesn't even make it in here
It's like you never signed up in the first place
Which is strange, cause looking at their codes, we receive code 200
Which means, the sign-up is in theory working
As far as I understand
Asiatic Lion
ahh~~ as you said, after creating signup, you should get verification link
Sun bearOP
I don't get it because I also verified my e-mail and spam folders
There is no verification e-mail
Asiatic Lion
to do that, await signUpAttempt.prepareEmailAddressVerification();
add this code right below the code signUp.create()
Sun bearOP
Asiatic Lion
signUpResult.prepareEmailAddressVerification({email_link: "email_link", email_link: your_login_url})
Sun bearOP
Asiatic Lion
change to prepareEmailAddressVerificationParams
Sun bearOP
Asiatic Lion
Oh no... my brain is boiling now...

signUpResult.prepareEmailAddressVerification({strategy: "email_link", redirectUrl: your_login_url})
change your_login_url to your real url...
@Asiatic Lion Oh no... my brain is boiling now... signUpResult.prepareEmailAddressVerification({strategy: "email_link", redirectUrl: your_login_url})
Sun bearOP
That one worked!

Now for login url does it want my login page url or something from Clerk ?
Asiatic Lion
your login page url
Sun bearOP
app/[lang]/login/page.tsx
That's the url
Asiatic Lion
😆 then you need to get current lang first...
Sun bearOP
Did they just introduce AI to VSCode or what is going on
It didn't use to auto complete like this until now
Asiatic Lion
there's AI extensions for VSCode, but no idea if there's builtin AI feature...
Sun bearOP
It's posible it's from Cody or something
Asiatic Lion
anyway
redirectUrl: `/${lang}/login`
Sun bearOP
It gives some errors
@Asiatic Lion anyway redirectUrl: `/${lang}/login`
Asiatic Lion
edited.. you should end it with `
Sun bearOP
Still gives some errors
Saved by autocomplete
Alright, so we have more errors after redirection
And it did not send any verification e-mail, just checked.
Also why is it using that star viper URL when I have my own domain
It should be jobsbringer.com/whatever stuff it needs to do
Asiatic Lion
phew... sorry @Sun bear I need to be offline now.
Let's solve this after I'm back.
in the meantime, check this link.
https://github.com/clerk/clerk-react-examples/tree/main
@Asiatic Lion phew... sorry <@998405690718703696> I need to be offline now. Let's solve this after I'm back. in the meantime, check this link. https://github.com/clerk/clerk-react-examples/tree/main
Sun bearOP
No worries Witty, I can wait. Just let me know when you have some time to help me. I will reply as soon as I'm online as well.

I prefer waiting to not mess things up since authentication is a crucial part of my platform and I want to get it right.
Also thank you for helping me so far 🙏🏻
Sun bearOP
I've been reading a bit into it and it looks like they do not recommend using the Email Link strategy because it doesn't do that well against spam accounts. Basically they recommend verifying the account during the sign-up process.

https://clerk.com/blog/how-we-roll-email-verification
Sun bearOP
BINGO!
I think I managed to solve it!!!
Sun bearOP
How I solved it: With the help of Chat Gippitty and the example for the Sign-up process in here: https://clerk.com/docs/custom-flows/email-password

Thank you very much for your help as well Adam, and I hope you're having an awesome day!
Answer
Asiatic Lion
Wow,, glad to hear that.
sorry to not help you.
@Asiatic Lion sorry to not help you.
Sun bearOP
You did help, and it was also thanks to you that I managed to solve the issue! I'm now working on updating the login page as well since the log-in doesn't work at the moment.

Have an awesome day Adam 😁
Asiatic Lion
😆 You too.