User Authentication


Login user


use window.Fouita.User.login function to login your user

<!-- Login.svelte -->
<script>
 async function submit(){
   const res = await window.Fouita.User.login({email: user.Email, password: user.Password})
   if(res.user?.token){
     // redirect to home or refresh page with location.reload()
     window.location.href = "/"
   }else{
     error = res.user?.message ?? "Problem detected, try again later"
   }
 }
</script>

<!-- Code with inputs -->


Signup new user


window.Fouita.User.signup to sign up new user to your organization

<script>
 async function submit(){
   const res = await window.Fouita.User.signup({
      name: user.Pseudo,
      email: user.Email,
      password: user.Password
   })
  if(res.user?.token){
   // redirect to home or refresh page with location.reload()
   window.location.href = "/"
  }else{
   error = res.user?.message ?? "Problem detected, try again later"
  }
 }
</script>

<!-- Code with inputs -->


Reset password


2 functions needed to reset password:

1 -  window.Fouita.User.forgetPassword to send code to email
2-  window.Fouita.User.resetPassword sent with the code received to validate


<script>
 async function forgetPw(){
   const res = await window.Fouita.User.forgetPassword({email: user.email})
   if(!res.success){
    error = res.message ?? "Problem detected, try again later"
    return
   }
 }

 async function resetPw(){
  // user.code is the code received by email
  const res = await window.Fouita.User.resetPassword({
       emai: user.email,
       code: user.code,
       password: user.newPassword
  })
  if(res.success === false){
   error = res.message ?? "Problem detected, try again later"
   return
  }
 }
</script>

<!-- Code with inputs -->


API calls


When making API calls with an authenticated user, you can call fetch function with fouita options

let opts= window.Fouita.fetchOptions()
// this will have headers with Authorization Bearer Token and POST method by default
// change method to what your server needs
opts.method = "GET"

//call fetch
let resp = await fetch(YOUR_API, opts).then(res => res.json())

Since Fouita uses a third party server to authenticate users, cookies are not allowed in the incognito mode, if you use cookies on your server you might need to consider adding the following:

opts= {...window.Fouita.fetchOptions(), credentials: 'include'}


Manage your users


All signup users can be found in your organization space under fouita dashboard