summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/src/routes/user-menu.tsx
blob: e0931efd951c0cad6b4278f259f572fb23dc79a7 (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
import { action } from "@solidjs/router"
import { getRequestEvent } from "solid-js/web"
import { useAuthSession } from "~/context/auth.session"
import { Dropdown } from "~/component/dropdown"
import "./user-menu.css"

const logout = action(async () => {
  "use server"
  const auth = await useAuthSession()
  const event = getRequestEvent()
  const current = auth.data.current
  if (current)
    await auth.update((val) => {
      delete val.account?.[current]
      const first = Object.keys(val.account ?? {})[0]
      val.current = first
      event!.locals.actor = undefined
      return val
    })
}, "auth.logout")

export function UserMenu(props: { email: string | null | undefined }) {
  return (
    <div data-component="user-menu">
      <Dropdown trigger={props.email ?? ""} align="right">
        <a href="/auth/logout" data-slot="item">
          Logout
        </a>
      </Dropdown>
    </div>
  )
}