|
|
@@ -1,6 +1,20 @@
|
|
|
+import { useAuthSession } from "~/context/auth.session"
|
|
|
import { IconLogo } from "../component/icon"
|
|
|
-import "./workspace/workspace.css"
|
|
|
-import { RouteSectionProps } from "@solidjs/router"
|
|
|
+import "./workspace.css"
|
|
|
+import { action, redirect, RouteSectionProps } from "@solidjs/router"
|
|
|
+
|
|
|
+const logout = action(async () => {
|
|
|
+ "use server"
|
|
|
+ const auth = await useAuthSession()
|
|
|
+ const current = auth.data.current
|
|
|
+ if (current)
|
|
|
+ await auth.update((val) => {
|
|
|
+ delete val.account[current]
|
|
|
+ return val
|
|
|
+ })
|
|
|
+
|
|
|
+ return redirect("/")
|
|
|
+})
|
|
|
|
|
|
export default function WorkspaceLayout(props: RouteSectionProps) {
|
|
|
return (
|
|
|
@@ -13,7 +27,9 @@ export default function WorkspaceLayout(props: RouteSectionProps) {
|
|
|
</div>
|
|
|
<div data-slot="header-actions">
|
|
|
<span>[email protected]</span>
|
|
|
- <a href="/logout">Logout</a>
|
|
|
+ <form action={logout} method="post">
|
|
|
+ <button type="submit" formaction={logout}>Logout</button>
|
|
|
+ </form>
|
|
|
</div>
|
|
|
</header>
|
|
|
<div data-slot="content">{props.children}</div>
|