( options?: SignOutParams<R> )
| 253 | * [Documentation](https://next-auth.js.org/getting-started/client#signout) |
| 254 | */ |
| 255 | export async function signOut<R extends boolean = true>( |
| 256 | options?: SignOutParams<R> |
| 257 | ): Promise<R extends true ? undefined : SignOutResponse> { |
| 258 | const { callbackUrl = window.location.href } = options ?? {} |
| 259 | const baseUrl = apiBaseUrl(__NEXTAUTH) |
| 260 | const fetchOptions = { |
| 261 | method: "post", |
| 262 | headers: { |
| 263 | "Content-Type": "application/x-www-form-urlencoded", |
| 264 | }, |
| 265 | // @ts-expect-error |
| 266 | body: new URLSearchParams({ |
| 267 | csrfToken: await getCsrfToken(), |
| 268 | callbackUrl, |
| 269 | json: true, |
| 270 | }), |
| 271 | } |
| 272 | const res = await fetch(`${baseUrl}/signout`, fetchOptions) |
| 273 | const data = await res.json() |
| 274 | broadcast.post({ event: "session", data: { trigger: "signout" } }) |
| 275 | |
| 276 | if (options?.redirect ?? true) { |
| 277 | const url = data.url ?? callbackUrl |
| 278 | window.location.href = url |
| 279 | // If url contains a hash, the browser does not reload the page. We reload manually |
| 280 | if (url.includes("#")) window.location.reload() |
| 281 | // @ts-expect-error |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | await __NEXTAUTH._getSession({ event: "storage" }) |
| 286 | |
| 287 | return data |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Provider to wrap the app in to make session data available globally. |
no test coverage detected
searching dependent graphs…