DynamoDB: Can't Log In

Open
#6,880 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale

Research direction

Start with the adapter entry point at @web/lib/auth/nextAuthDynamoAdapter and the NextAuth configuration shown in the issue. Reproduce the Google sign-in using the database session strategy and inspect the adapter_getSessionAndUser flow described in the debug output. Done means database sessions complete sign-in and expose the expected user or account data, with a useful error when they do not.

Written by the indexing model from the issue text.

Description

adapters dynamodb triage
Adapter type

@next-auth/dynamodb-adapter

Environment

System:
OS: macOS 13.2
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 853.02 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.0 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 9.2.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 110.1.48.171
Chrome: 109.0.5414.87
Firefox: 105.0.3
Safari: 16.3

npmPackages:
@next-auth/dynamodb-adapter: ^3.0.1 => 3.0.1

Reproduction URL

none

Describe the issue

I followed the instructions here exactly: https://next-auth.js.org/adapters/dynamodb

When I try to sign in with the Google provider, I am not signed in, and there is no error message. I see the account/user/sessions created in the DB:

Screenshot 2023-03-05 at 6 11 43 PM

If I switch strategy to jwt then everything works perfectly except I don't have access to the user/account inside my session. Using the default database provider simply fails to log me in.

How to reproduce
import { nextAuthDynamoAdapter } from "@web/lib/auth/nextAuthDynamoAdapter"
import NextAuth, { NextAuthOptions } from "next-auth"
import GoogleProvider from "next-auth/providers/google"

export const authOptions: NextAuthOptions = {
  providers: [
    GoogleProvider({ 
// yes these are correct
      clientId: process.env.GOOGLE_CLIENT_ID || "",
      clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
    }),
  ],
  adapter: nextAuthDynamoAdapter,
  // session: {
  //   strategy: "jwt",
  //   maxAge: 90 * 24 * 60 * 60, // 90 days, change it as you like
  // },
  callbacks: {
  },
}
export default NextAuth(authOptions)

Sign in with google
You are not logged in, nothing in console or logs

Set strategy to jwt and you can log in fine

Expected behavior

I would like access to the account/user objects in my session. What I would like to do is create objects in the DB attached to a user, but I don't have a way to get the userid/accountid if I'm using the jwt strategy. I'd be happy to use the database strategy but it's unclear to my why I simply can't log in when using it because the data appears correctly in the DB, the next-auth.session-token cookie is set, and I can log in okay when using the jwt strategy. And there is no useful output in the browser or server.

If I enable debug I have this output:

[next-auth][debug][OAUTH_CALLBACK_RESPONSE] {
  profile: {
...
  },
  account: {
    provider: 'google',
    type: 'oauth',
...
    token_type: 'Bearer',
    id_token: 'xxx'
  },
  OAuthProfile: {
    xxx
    iat: 1678085335,
    exp: 1678088935
  }
}
[next-auth][debug][adapter_getUserByAccount] {
  args: [
    { providerAccountId: 'xxx', provider: 'google' }
  ]
}
[next-auth][debug][adapter_getSessionAndUser] { args: [ '4dede7fc-8cba-4c40-8158-xxx' ] }
[next-auth][debug][adapter_getUserByAccount] {
  args: [
    { providerAccountId: 'xxx', provider: 'google' }
  ]
}

But it just kicks me back to the login screen if using strategy 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.