feat: new session api

This commit is contained in:
DIYgod
2024-04-27 21:28:51 +08:00
parent 8f02fb1432
commit 0b907292b7
+27 -5
View File
@@ -1,7 +1,27 @@
import { Button } from "@renderer/components/ui/button"
import { UserButton } from "@renderer/components/user-button"
import { getCsrfToken, authConfigManager } from "@hono/auth-js/react"
export function Component() {
const getCallbackUrl = async () => {
const response = await (
await fetch(
`${authConfigManager.getConfig().baseUrl}/auth-app/new-session`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
csrfToken: await getCsrfToken(),
}),
},
)
).json()
return `readok://auth?token=${response.data.sessionToken}`
}
return (
<div className="h-screen w-full flex items-center justify-center flex-col gap-10">
<UserButton />
@@ -12,11 +32,13 @@ export function Component() {
You have successfully connected to ReadOK Account. Now is the time to
open ReadOK and safely close this page.
</h2>
<a href={`readok://todo`} className="flex flex-col gap-3">
<Button className="text-lg" size="xl">
Open ReadOK
</Button>
</a>
<Button
className="text-lg"
size="xl"
onClick={async () => window.open(await getCallbackUrl())}
>
Open ReadOK
</Button>
</div>
)
}