( options?: SignOutParams<R> )
| 328 | * |
| 329 | */ |
| 330 | export async function signOut<R extends boolean = true>( |
| 331 | options?: SignOutParams<R> |
| 332 | ): Promise<R extends true ? undefined : SignOutResponse> { |
| 333 | const { callbackUrl = window.location.href } = options || {}; |
| 334 | const baseUrl = __LINEN_AUTH.basePath; |
| 335 | const fetchOptions = { |
| 336 | method: 'post', |
| 337 | headers: { |
| 338 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 339 | }, |
| 340 | // @ts-expect-error |
| 341 | body: new URLSearchParams({ |
| 342 | csrfToken: await getCsrfToken(), |
| 343 | callbackUrl, |
| 344 | json: true, |
| 345 | }), |
| 346 | }; |
| 347 | const res = await fetch(`${baseUrl}/signout`, fetchOptions); |
| 348 | const data = await res.json(); |
| 349 | cleanUpStorage(); |
| 350 | |
| 351 | broadcast.post({ event: 'session', data: { trigger: 'signout' } }); |
| 352 | |
| 353 | window.location.href = callbackUrl; |
| 354 | await __LINEN_AUTH._getSession({ event: 'storage' }); |
| 355 | |
| 356 | return data; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Provider to wrap the app in to make session data available globally. |
no test coverage detected