Sveltekit + surrealdb-adapter + email magic link login does not work

Open
#9,441 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Clone the reproduction repository and follow README.md to configure the environment, start SurrealDB, and run the SvelteKit development server. Reproduce the magic-link login and inspect the @auth/core/lib/utils/web.js stack entry alongside the adapter session data. Done means the callback completes without the expires error, a login cookie is saved, and the user is logged in.

Written by the indexing model from the issue text.

Description

bug triage
Environment

System:
OS: Linux 6.5 Pop!_OS 22.04 LTS
CPU: (12) x64 AMD Ryzen 5 5625U with Radeon Graphics
Memory: 8.56 GB / 14.97 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 20.2.0 - ~/.asdf/installs/nodejs/20.2.0/bin/node
npm: 9.6.6 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 8.12.1 - ~/.local/share/pnpm/pnpm
bun: 0.7.3 - ~/.bun/bin/bun
Browsers:
Chromium: 120.0.6099.71
npmPackages:
@auth/core: ^0.19.0 => 0.19.0
@auth/surrealdb-adapter: ^0.2.6 => 0.2.6
@auth/sveltekit: ^0.5.0 => 0.5.0

Reproduction URL

https://github.com/Z-snails/authjs-email-error

Describe the issue

When signing in with email, after clicking the sign in link in the email, the following error occurs (with full log of a sign in)

[auth][error] TypeError: option expires is invalid
[auth][warn][debug-enabled] Read more: https://warnings.authjs.dev#debug-enabled
[auth][debug]: adapter_getUserByEmail {
  "args": [
    "<my email>"
  ]
}
[auth][debug]: adapter_createVerificationToken {
  "args": [
    {
      "identifier": "<my email>",
      "token": "...",
      "expires": "2023-12-23T09:40:26.862Z"
    }
  ]
}
[auth][debug]: adapter_useVerificationToken {
  "args": [
    {
      "identifier": "<my email>",
      "token": "..."
    }
  ]
}
[auth][debug]: adapter_getUserByEmail {
  "args": [
    "<my email>"
  ]
}
[auth][debug]: adapter_getUserByEmail {
  "args": [
    "<my email>"
  ]
}
[auth][debug]: adapter_updateUser {
  "args": [
    {
      "id": "⟨b204504e-3d69-4dbb-af93-9b5cddcabcdc⟩",
      "emailVerified": "2023-12-22T09:40:40.114Z"
    }
  ]
}
[auth][debug]: adapter_createSession {
  "args": [
    {
      "sessionToken": "...",
      "userId": "⟨b204504e-3d69-4dbb-af93-9b5cddcabcdc⟩",
      "expires": "2024-01-21T09:40:40.115Z"
    }
  ]
}
[auth][error] TypeError: option expires is invalid
    at serialize (~/auth-test/node_modules/.pnpm/cookie@0.6.0/node_modules/cookie/index.js:161:13)
    at ~/auth-test/node_modules/.pnpm/@auth+core@0.19.0_nodemailer@6.9.7/node_modules/@auth/core/lib/utils/web.js:76:30
    at Array.forEach (<anonymous>)
    at toResponse (~/auth-test/node_modules/.pnpm/@auth+core@0.19.0_nodemailer@6.9.7/node_modules/@auth/core/lib/utils/web.js:74:18)
    at Module.Auth (~/auth-test/node_modules/.pnpm/@auth+core@0.19.0_nodemailer@6.9.7/node_modules/@auth/core/index.js:107:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.respond (~/auth-test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/runtime/server/respond.js:291:20)
    at async ~/auth-test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:502:22
q
How to reproduce
  • Clone the github repo (https://github.com/Z-snails/authjs-email-error)
  • Install the deps (with pnpm install or npm install)
  • See README.md for how to configure .env (I used sendgrid as the email server)
  • Start the surreal server with surreal start (helpful to use tmux or similar)
  • Start the dev server npm dev
  • Open in browser
  • Click Sign In
  • Enter email address
  • Click on link in email
Expected behavior

I should be logged in and a login cookie should be saved in my browser. Neither of these occur, instead an error 500 is returned.

Although the user shows as verified in the database.

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

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.

More from nextauthjs/next-auth

All issues in nextauthjs/next-auth

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.