myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

Auth.jsx (1420B)


      1 import { useState } from 'react'
      2 import { supabase } from './supabaseClient'
      3 
      4 function Auth() {
      5   const [loading, setLoading] = useState(false)
      6   const [email, setEmail] = useState('')
      7 
      8   const handleLogin = async (e) => {
      9     e.preventDefault()
     10 
     11     try {
     12       setLoading(true)
     13       const { error } = await supabase.auth.signInWithOtp({
     14         email: email,
     15         options: {
     16           shouldCreateUser: false,
     17           emailRedirectTo: window.location.origin
     18         }})
     19       if (error) throw error
     20       alert('Check your email for the login link!')
     21     } catch (error) {
     22       alert(error.error_description || error.message)
     23     } finally {
     24       setLoading(false)
     25     }
     26   }
     27 
     28   return (
     29     <div className="Auth">
     30       <div>
     31         <button disabled={!loading}>{loading ? '🛸 sending magic link ...' : ''}</button>
     32         <h1>Login</h1>
     33         <p>Sign in with a magic link.</p>
     34         <div className='loginForm'>
     35           <form onSubmit={handleLogin}>
     36             <input
     37               id="email"
     38               type="email"
     39               placeholder="Your email"
     40               value={email}
     41               onChange={(e) => setEmail(e.target.value)}
     42             /><br/>
     43             <button>🛸 Send magic link</button>
     44           </form>
     45         </div>
     46         <h1>Registration</h1>
     47         <p>No account yet? Contact event administrator to sign up.</p>
     48       </div>
     49     </div>
     50   )
     51 }
     52 
     53 export default Auth;