๐Ÿ“ฆ nrjdalal / better-next

๐Ÿ“„ auth.tsx ยท 57 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57"use client"

import { authClient } from "@/lib/auth/client"
import { useRouter } from "next/navigation"

export const SignIn = () => {
  const router = useRouter()

  return (
    <button
      onClick={async () => {
        await authClient.signIn.email({
          email: "johndoe@acme.com",
          password: "JohnDoeAcmeCom",
        })
        router.refresh()
      }}
    >
      Sign in
    </button>
  )
}

export const SignUp = () => {
  const router = useRouter()

  return (
    <button
      onClick={async () => {
        await authClient.signUp.email({
          name: "John Doe",
          email: "johndoe@acme.com",
          password: "JohnDoeAcmeCom",
        })
        router.refresh()
      }}
    >
      Sign up
    </button>
  )
}

export const SignOut = () => {
  const router = useRouter()

  return (
    <button
      onClick={async () => {
        await authClient.signOut()
        router.refresh()
      }}
    >
      Sign out
    </button>
  )
}