Yes I save it a data set which is linked to a dynamic profile creation page.
I tried doing the same thing you explained for the login by keeping the data set in the backend. I created two jsw files, “parentProfile” and “studentProfile”
The back end code for parentProfile and studentProfile checks for the first input in the dyanmic dataset i.e. firstName and also checks for a boolean field named “profileCreated” if its true then profile was created
Code for parentProfile jsw
import wixData from ‘wix-data’ ;
export async function checkForProfile ( firstName ) {
// convert email to uppercase, remove all spaces
**let** scrubbedFirstName = firstName . toUpperCase (). split ( " " ). join ( "" );
**let** options = {
"suppressAuth" : **true** ,
"suppressHooks" : **true**
};
**return** wixData . query ( "Parent_profile" )
. eq ( "firstName" , scrubbedFirstName )
. find ( options )
. then ( ( results ) => {
**if** ( results . items . length == 0 ) {
// didn't find email in table so save it
**let** toInsert = {
"firstName" : scrubbedFirstName ,
"profileCreated" : **true**
}
wixData . insert ( "submit" , toInsert , options )
**return** **false** ;
} **else** {
//found email
**return** **true** ;
}
})
. **catch** ( ( error ) => {
console . log ( "[parentProfile:]\n" + error . message );
})
}
code for studentProfile;
import wixData from ‘wix-data’ ;
export async function checkForProfile ( firstName ) {
// convert email to uppercase, remove all spaces
**let** scrubbedFirstName = firstName . toUpperCase (). split ( " " ). join ( "" );
**let** options = {
"suppressAuth" : **true** ,
"suppressHooks" : **true**
};
**return** wixData . query ( "Student_profile" )
. eq ( "firstName" , scrubbedFirstName )
. find ( options )
. then ( ( results ) => {
**if** ( results . items . length == 0 ) {
// didn't find email in table so save it
**let** toInsert = {
"firstName" : scrubbedFirstName ,
"profileCreated" : **true**
}
wixData . insert ( "submit" , toInsert , options )
**return** **false** ;
} **else** {
//found email
**return** **true** ;
}
})
. **catch** ( ( error ) => {
console . log ( "[studentProfile:]\n" + error . message );
})
}
I also modified my login front end this way by addding
import { checkForProfile } from ‘backend/parentProfile’ ; ‘backend/studentProfile’ ;
frontend code;
import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;
import { checkUserEmail } from ‘backend/checkRegistered’ ;
import { checkForProfile } from ‘backend/parentProfile’ ; ‘backend/studentProfile’ ;
export function loginNow ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
let emaail = $w ( “#loginEmail” ). value
let password = $w ( “#loginPassword” ). value
wixUsers . login ( emaail , password )
. then (() => {
console . log ( “user logged in” )
})
. catch (( err ) => {
console . log ( err )
})
}
$w . onReady ( async function () {
wixUsers . onLogin (( user )=>{
user . getEmail ()
. then ( ( email ) => {
$w . onReady ( **async function** () {
**let** found = **await** checkUserEmail ( email );
**if** ( ! found ) {
// user is new, never logged in before
wixLocation . to ( "/registration-moreinfo" );
} **else** {
// user was found, previously logged in
**let** found = **await** checkForProfile ( email );
user . getRoles ()
. then (( roles ) =>{
**let** role = roles [ 0 ]
**let** roleName = role . name
**if** ( roleName === "Parents" ) {
wixLocation . to ( "/parent-profile/" );
} **else if** ( roleName === "Class XI & XII - Applied Mathematics" ) {
wixLocation . to ( "/student-profile/" );
} **else if** ( roleName === "Mathematics - Class XI - JEE" ) {
wixLocation . to ( "/student-profile/" );
} **else if** ( roleName === "Mathematics - Class XII - JEE" ) {
wixLocation . to ( "/student-profile/" );
} **else if** ( roleName === "Chemistry - Class XII - JEE/NEET" ) {
wixLocation . to ( "/student-profile/" );
} **else if** ( roleName === "Chemistry - Class XI - JEE/NEET" ) {
wixLocation . to ( "/student-profile/" );
}
})
}
})
})
})
})
Is all of this correct?? please check
Again thanks for helping me and I am also learning from your explanations