MCPcopy
hub / github.com/nextauthjs/next-auth / signOut

Function signOut

src/react/index.tsx:255–288  ·  view source on GitHub ↗
(
  options?: SignOutParams<R>
)

Source from the content-addressed store, hash-verified

253 * [Documentation](https://next-auth.js.org/getting-started/client#signout)
254 */
255export 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.

Callers 4

sign-out.test.jsFile · 0.90
handleLogoutFunction · 0.90
handleLogoutFunction · 0.90

Calls 2

apiBaseUrlFunction · 0.90
getCsrfTokenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…