Hello @Paul Krzyz. Thank you for your help. This is what I have in my backend code:
import wixData from ‘wix-data’ ;
export async function checkUserExists ( email ){
if(typeof email !== ‘undefined’ && email !== “” ){
let options = {
“suppressAuth” : true ,
“suppressHooks” : true ,
};
//convert to lowercase and remove spaces
**var** _email = email . toLowerCase (). split ( " " ). join ( "" );
**var** url = "" ;
**return** **await** wixData . query ( "Teachers" )
. eq ( 'email' , _email )
. find ( options )
. then ( ( results ) =>{
**if** ( results.items.length != 0 ) {
//returns the first row, if multiple rows with the same email are found
url = results.items [ 0 ]. link-teachers-title ;
**return** url ;
} **else** {
**return** "Error: User not setup. contact admin for help." ;
}
})
. **catch** (( error ) =>{
console . log ( "Error reading from table: Teachers.\n" + error.message );
**return** "Error: Fetch error trying to get data from table Teachers" ;
});
}
**else** {
**return** "Error: Email parameter passed in was invalid"
}
}
This is what I put in my login page
import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;
import { checkUserExists } from ‘backend/login_functions’
let userEmail = “” ;
$w . onReady ( function (){
})
export async function loginTeacher_click ( event ){
userEmail = $w ( ‘#emailLogin’ ). value . toLowerCase (). split ( " " ). join ( “” );
let password = $w ( ‘#passwordLogin’ ). value ;
wixUsers . login ( userEmail,password )
. then ( () => {
let newLink = await checkUserExists ( userEmail );
if ( newLink . substring ( 0,5 ) !== “Error” ){
let realLink = “/teachers/profile/” + newLink ;
console . log ( realLink );
wixLocation . to ( realLink );
} else {
console . log ( “Error occured: \n” + newLink );
}
})
. catch (( error ) =>{
console . log ( error );
})
}
However, when I run the backend program, it gives me this message: Error reading from table: Teachers. teachers is not defined
Also await is underlined in read saying it can only be used in an async function, but I believe I am using it in an async function