docs: update waku usage (#7842)

This commit is contained in:
Alex Yang
2026-02-07 17:04:04 +00:00
committed by GitHub
parent dd6dc4601f
commit 54c6e84b6e
+16 -14
View File
@@ -73,12 +73,13 @@ The `api` object exported from the auth instance contains all the actions that y
"use server" // Waku currently only supports file-level "use server"
import { auth } from "./auth"
import { unstable_getContext as getContext } from "waku/server"
import { unstable_getHeaders as getHeaders } from "waku/server"
export const someAuthenticatedAction = async () => {
"use server"
const headers = getHeaders()
const session = await auth.api.getSession({
headers: new Headers(getContext().req.headers),
headers,
})
};
```
@@ -88,20 +89,21 @@ export const someAuthenticatedAction = async () => {
```tsx
import { auth } from "../auth"
import { unstable_getContext as getContext } from "waku/server"
import { unstable_getHeaders as getHeaders } from "waku/server"
export async function ServerComponent() {
const session = await auth.api.getSession({
headers: new Headers(getContext().req.headers),
})
if(!session) {
return <div>Not authenticated</div>
}
return (
<div>
<h1>Welcome {session.user.name}</h1>
</div>
)
const headers = getHeaders()
const session = await auth.api.getSession({
headers,
})
if(!session) {
return <div>Not authenticated</div>
}
return (
<div>
<h1>Welcome {session.user.name}</h1>
</div>
)
}
```