nextauthjs / nextauthjs/next-auth

SvelteKit `locals.signOut/signIn` never set

Open
#13,112 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Environment
  System:
    OS: macOS 15.0.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 90.55 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.7.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 10.11.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 138.0.7204.101
    Safari: 18.0.1
  npmPackages:
    @auth/core: ^0.40.0 => 0.40.0 
    @auth/drizzle-adapter: ^1.10.0 => 1.10.0 
    @auth/sveltekit: ^1.10.0 => 1.10.0 
Reproduction URL

https://github.com/coryvirok/nextauth-locals-bug

Describe the issue

The SvelteKit types say that Locals includes signOut and signIn functions but neither exist.

https://github.com/nextauthjs/next-auth/blob/main/packages/frameworks-sveltekit/src/lib/types.ts

The repro shows that locals.auth() exists but the others do not.

locals includes auth()? true
locals includes signIn()? false
locals includes signOut()? false
TypeError: event.locals.signOut is not a function

My use case is that I want to have a src/routes/logout/+server.js endpoint that simply logs out the user when they navigate to the URL and then redirects them to the homepage. I tried using the SvelteKitAuth.signOut function, but it appears that is only meant to handle form Actions. If called directly, it results in the error: TypeError: Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".

E.g.

// src/routes/logout/+server.ts

import type { RequestEvent } from '@sveltejs/kit'
import { signOut } from '$lib/server/auth'

export async function GET(event: RequestEvent) {
  await signOut(event)  // Results in TypeError: Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".
  // await event.locals.signOut({ redirectTo: '/' })  // event.locals.signOut is not a function
}
How to reproduce

Go here and click on the "Logout" link.

https://stackblitz.com/~/github.com/coryvirok/nextauth-locals-bug?file=src/hooks.server.js

Expected behavior

locals.signOut() should exist and match the signature in types.ts.


And unrelated to the bug, you REALLY need to fix the GH issue submission process. I spent ~30 minutes creating a repro in Stackblitz, describing the bug in GH only to hit "Create" and have the Issue auto-rejected because the repro wasn't a GitHub URL. Then I spent another 15 minutes creating a new Issue and a GH repro with the Stackblitz project to satisfy the GH Issue validation requirements.

I bet folks give up on submitting issues. Please loosen the requirements.

Lastly, thank you for this project.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/frameworks-sveltekit/src/lib/types.ts and compare its Locals declarations with the SvelteKit locals setup shown in the reproduction. Run the linked reproduction and inspect the logout endpoint behavior. Done means locals.signIn() and locals.signOut() exist with the documented signature and the reported TypeError no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.