nextauthjs / nextauthjs/next-auth
svelteKit: getToken return null
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: macOS 12.6
CPU: (48) x64 Intel(R) Xeon(R) W-3265M CPU @ 2.70GHz
Memory: 107.02 GB / 192.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.16.0 - /usr/local/bin/node
npm: 8.11.0 - /usr/local/bin/npm
Browsers:
Chrome: 109.0.5414.87
Firefox Developer Edition: 110.0
Safari: 16.0
Reproduction URL
https://github.com/rolanday/skit-authjs
Describe the issue
getToken returns null
https://github.com/rolanday/skit-authjs/blob/main/src/routes/api/%2Bserver.ts
import type { RequestHandler } from '@sveltejs/kit';
import { getToken } from '@auth/core/jwt';
export const GET: RequestHandler = async ({ request }) => {
const jwt = await getToken({ req: request, secret: 's3cr3t' });
return new Response(String(jwt));
};
How to reproduce
Code minor fork off official next-auth from here:
https://github.com/nextauthjs/next-auth/tree/main/apps/examples/sveltekit
Use sample to sign-in, and verify JWT token is present (it is). Then make API call to http://localhost:5173/api using from same browser as signed in. getToken return nujl.
import type { RequestHandler } from '@sveltejs/kit';
import { getToken } from '@auth/core/jwt';
export const GET: RequestHandler = async ({ request }) => {
const jwt = await getToken({ req: request, secret: 's3cr3t' }); // <<======
return new Response(String(jwt));
};
Expected behavior
Expect to get back unencrypted token (same behavior as get making getToken call from Nex.js).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/routes/api/+server.ts and reproduce the request using the linked SvelteKit example and the provided getToken call. Compare the SvelteKit request handling with the Next.js usage, then verify that the API response returns the unencrypted token rather than null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100