I have an account page, which the user ends up after signing up. As soon as they hit this page, I would like to create a profile row with a 1-1 mapping to a (Supabase) users table.
If this would be a client side page, I would do something like this:
const ProfilePage: FC<{ userId: string }> = ({ userId }) => {
const [profile, setProfile] = useState<Profile | null>(null);
useEffect(() => {
getProfile().then(profile => {
if (profile) {
setProfile(profile)
} else {
createProfile({ user_id: userId, name: email.split("@")[0], avatar: null })
.then(setProfile)
}
})
}, [])
return profile ? (
<div>Welcome, {profile.name}</div>
) : (
<div>Loading your profile / setting up your profile ...</div>
)
}
Now I want to do this in a server component. If I understand correctly, useEffect()
is a client-side hook. How do I check if something exists, run something, and make sure to re-render the page as soon as the profile has been created?