summaryrefslogtreecommitdiff
path: root/frontend/components/auth/AuthButtons.tsx
blob: eea9f916e96790ba570c9091f5a5712e5750724b (plain)
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
import { LogIn, LogOut, Clock } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Auth_get_user } from "@/lib/auth"
import { Auth_tinyauth_public_endpoint } from "@/lib/auth_shared"
import Link from "next/link"

export async function AuthButtons() {
  const user = await Auth_get_user()

  if (user.isLoggedIn) {
    return (
      <div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
        <span className="text-sm text-muted-foreground">{user.email}</span>
        <div className="flex items-center gap-2 sm:gap-3">
          <Link href="/history">
            <Button variant="outline" size="sm">
              <Clock className="mr-2 h-4 w-4" />
              History
            </Button>
          </Link>
          <form action="/logout" method="post">
            <Button type="submit" variant="outline">
              <LogOut className="mr-2 h-4 w-4" />
              Logout
            </Button>
          </form>
        </div>
      </div>
    )
  }

  const authUrl = `${Auth_tinyauth_public_endpoint()}/login`

  return (
    <div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
      <Link href="/history">
        <Button variant="outline" size="sm">
          <Clock className="mr-2 h-4 w-4" />
          History
        </Button>
      </Link>
      <Button asChild>
        <a href={authUrl}>
          <LogIn className="mr-2 h-4 w-4" />
          Login
        </a>
      </Button>
    </div>
  )
}