Skip to content

DynamoDB: Can't Log In #6880

@revmischa

Description

@revmischa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    adaptersChanges related to the core code concerning database adaptersdynamodb@auth/dynamodb-adaptertriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions