summaryrefslogtreecommitdiff
path: root/frontend/components/auth/AuthButtons.tsx
blob: 5b5053dcdce88c3796062b1d9df22e29dd84e58e (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
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 (
      <form action="/api/logout" method="post">
        <Button type="submit" variant="outline">
          <LogOut className="mr-2 h-4 w-4" />
          Logout
        </Button>
      </form>
    )
  }
  
  const authUrl = `${Auth_tinyauth_public_endpoint()}/auth/google`
  
  return (
    <Button asChild>
      <a href={authUrl}>
        <LogIn className="mr-2 h-4 w-4" />
        Login
      </a>
    </Button>
  )
}