Next.js Discord

Discord Forum

How do I make users enter additional info when signing up using Google?

Unanswered
Sirex woodwasp posted this in #help-forum
Open in Discord
Sirex woodwaspOP

22 Replies

@Sirex woodwasp Click to see attachment
German yellowjacket
after google signin redirect them to a form and do not allow them to access the application until that form is complete.
@German yellowjacket after google signin redirect them to a form and do not allow them to access the application until that form is complete.
Sirex woodwaspOP
well i just don't know how to actually write code ? could you please show me how or show me direction?
@Sirex woodwasp well i just don't know how to actually write code ? could you please show me how or show me direction?
German yellowjacket
do you already have the google sign in setup
Sirex woodwaspOP
yes
German yellowjacket
do you have a database set up too
Sirex woodwaspOP
yes
supabase
that's my code right now
somehow I got it to send me to the form page
German yellowjacket
Never used supabase. What you could is after signup you add a callback function that redirects them to a new page with a form on it. The user is prompted to fill out that form. Once that form is filled out then they can hit the submit or button and it can redirect them to their home page or just use a state variable to ensure they submitted the info and it'll change the component displayed on that page.
Sirex woodwaspOP
and then when I submit the form, it does not do anything
export default function CollectInfo() {
const [formData, setFormData] = useState({
phoneNumber: '',
gender: '',
firstName: '',
lastName: '',
dateOfBirth: '',
});
const router = useRouter();




const handleChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};

const handleSubmit = async (e) => {
e.preventDefault();

const result = await signIn('credentials', {
redirect: false,
// callbackUrl,
...formData
});

if (result?.url) {
router.push(result.url);
} else {
console.error('Sign-in failed');
}
};

return (
<form onSubmit={handleSubmit}>
<label>
First Name:
<input
type="text"
name="firstName"
value={formData.firstName}
onChange={handleChange}
required
/>
</label>
<label>
Last Name:
<input
type="text"
name="lastName"
value={formData.lastName}
onChange={handleChange}
required
/>
</label>
<label>
Phone Number:
<input
type="text"
name="phoneNumber"
value={formData.phoneNumber}
onChange={handleChange}
required
/>
</label>
<label>
Gender:
<select
name="gender"
value={formData.gender}
onChange={handleChange}
required
>
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</label>
<label>
Date of Birth:
<input
type="date"
name="dateOfBirth"
value={formData.dateOfBirth}
onChange={handleChange}
required
/>
</label>
<button type="submit">Submit</button>
</form>
);
}
thats my form
async signIn({ user, account, profile }) {
try {
const existingUser = await getSubscriber(user.email);

if (!existingUser) {

const requiredFields = ['phoneNumber', 'gender', 'firstName', 'lastName', 'dateOfBirth'];

const hasAllFields = requiredFields.every(field => account[field]);

if (!hasAllFields) {
// Redirect to data collection page if any required field is missing
throw new Error('Required information not provided');
}
await createSubscriber({
email: user.email,
name: ${account.firstName} ${account.lastName},
phoneNumber: account.phoneNumber,
gender: account.gender,
firstName: account.firstName,
lastName: account.lastName,
dateOfBirth: account.dateOfBirth,
});
}

return true;
} catch (error) {
if (error.message === 'Required information not provided') {
// Redirect to the data collection page with a callback URL
const redirectUrl = /collect-info?callbackUrl=${encodeURIComponent(process.env.NEXTAUTH_URL)};
return redirectUrl;
}
return false;
}


},
this is signin callback
i think something wrong with this part const redirectUrl = /collect-info?callbackUrl=${encodeURIComponent(process.env.NEXTAUTH_URL)};
return redirectUrl;
any idea?
and how can I write in the Discussions?
German yellowjacket
is the user already signed in via google?
You need to implement api to handle the form submit