summaryrefslogtreecommitdiff
path: root/frontend/components/auth/AuthButtons.tsx
blob: cfa69fee048da6a8b659e3f2f005817aac32860e (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
import { LogIn, LogOut } 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"

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

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

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

  return (
    <Button asChild>
      <a href={authUrl}>
        <LogIn className="mr-2 h-4 w-4" />
        Login
      </a>
    </Button>
  )
}