Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use client'
- import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
- import { useRouter } from 'next/navigation'
- import { useState } from 'react'
- import type { Database } from '../../lib/supabase.types'
- export default function Login() {
- const [email, setEmail] = useState('')
- const [password, setPassword] = useState('')
- const router = useRouter()
- const supabase = createClientComponentClient<Database>()
- const handleSignUp = async () => {
- await supabase.auth.signUp({
- email,
- password,
- options: {
- emailRedirectTo: `${location.origin}/auth/callback`,
- },
- })
- router.refresh()
- }
- const handleSignIn = async () => {
- await supabase.auth.signInWithPassword({
- email,
- password,
- })
- router.refresh()
- }
- const handleSignOut = async () => {
- await supabase.auth.signOut()
- router.refresh()
- }
- const getUser = async () => {
- const { data, error } = await supabase.auth.getSession()
- console.log("Data is", data) -> returns session: null
- return data
- }
- console.log("supabase user is", getUser()) <- returns promis <state>: "pending"
- return (
- <>
- <input name="email" onChange={(e) => setEmail(e.target.value)} value={email} />
- <input
- type="password"
- name="password"
- onChange={(e) => setPassword(e.target.value)}
- value={password}
- />
- <button onClick={handleSignUp}>Sign up</button>
- <button onClick={handleSignIn}>Sign in</button>
- <button onClick={handleSignOut}>Sign out</button>
- </>
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment