Skip to content

Commit fe008b6

Browse files
thdxrrekram1-node
authored andcommitted
fix logout
1 parent 641f0da commit fe008b6

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { redirect } from "@solidjs/router"
2+
import { APIEvent } from "@solidjs/start"
3+
import { getResponseHeaders } from "@solidjs/start/http"
4+
import { useAuthSession } from "~/context/auth.session"
5+
6+
export async function GET(event: APIEvent) {
7+
const auth = await useAuthSession()
8+
const current = auth.data.current
9+
if (current)
10+
await auth.update((val) => {
11+
delete val.account?.[current]
12+
const first = Object.keys(val.account ?? {})[0]
13+
val.current = first
14+
event!.locals.actor = undefined
15+
return val
16+
})
17+
return redirect("/zen", {
18+
status: 302,
19+
headers: getResponseHeaders(),
20+
})
21+
}

packages/console/app/src/routes/user-menu.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
[data-slot="item"] {
1414
color: var(--color-danger);
15+
text-decoration: none;
1516
}
1617
}
1718
}

packages/console/app/src/routes/user-menu.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { action, redirect } from "@solidjs/router"
1+
import { action } from "@solidjs/router"
22
import { getRequestEvent } from "solid-js/web"
33
import { useAuthSession } from "~/context/auth.session"
44
import { Dropdown } from "~/component/dropdown"
55
import "./user-menu.css"
6-
import { getResponseHeaders } from "@solidjs/start/http"
76

87
const logout = action(async () => {
98
"use server"
@@ -18,21 +17,15 @@ const logout = action(async () => {
1817
event!.locals.actor = undefined
1918
return val
2019
})
21-
throw redirect("/zen", {
22-
status: 302,
23-
headers: getResponseHeaders(),
24-
})
25-
})
20+
}, "auth.logout")
2621

2722
export function UserMenu(props: { email: string | null | undefined }) {
2823
return (
2924
<div data-component="user-menu">
3025
<Dropdown trigger={props.email ?? ""} align="right">
31-
<form action={logout} method="post">
32-
<button type="submit" formaction={logout} data-slot="item">
33-
Logout
34-
</button>
35-
</form>
26+
<a href="/auth/logout" data-slot="item">
27+
Logout
28+
</a>
3629
</Dropdown>
3730
</div>
3831
)

0 commit comments

Comments
 (0)