Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB Adapter can create but cannot retrieve sessions from database when using useSession() and strategy:"database" #10897

Open
avi312singh opened this issue May 13, 2024 · 0 comments
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@avi312singh
Copy link

avi312singh commented May 13, 2024

Adapter type

@auth/dynamodb-adapter

Environment

  System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 86.53 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.5.0 - ~/.nvm/versions/node/v21.5.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v21.5.0/bin/npm
  Browsers:
    Chrome: 124.0.6367.201
    Safari: 17.4.1
  npmPackages:
    next: ^13.5.6 => 13.5.6 
    next-auth: ^4.24.5 => 4.24.7 
    react: 18.2.0 => 18.2.0 
    next-auth/dynamodb-adapter: 3.0.2 => 3.0.2

Reproduction URL

https://github.com/NHSDigital/Galleri-Frontend/blob/spike/next-authv4/src/app/api/auth/%5B...nextauth%5D/route.ts

Describe the issue

This code succesfully generates session in our dynamoDb table which we have specified using a custom name when a user authenticates with either of our two providers, as seen in screenshot below:

image

The screenshot shows the newly created session within dynamoDb after the user attempts to authenticate next-auth routes them back to the signin page, as the session cannot be retrieved.

However when attempting to retrieve the session before landing on the authenticated protected page, the useSession() hook retrieves null for the session.

Loading status:
image

Resolved status:
image

The authentication was fully working before this relatively small PR, ignore the fact that no credentials are provided as we are using roles within IAM so that the frontend has access to the table within dynamoDb. As sessions are being succesfully created in the table specified, the roles have been setup correctly.

How to reproduce

  • Migrate from JWT to database strategy
  • Use client side useSession() hook to retrieve session and check if user is authenticated before rendering protected page
  • Authentication will break and next-auth will redirect to sign in page

Expected behavior

  • Migrate from JWT to database strategy
  • Use client side useSession() hook to retrieve session and check if user is authenticated before rendering protected page
  • Authentication will continue to work after migration from JWT and next-auth will redirect to a protected page
@avi312singh avi312singh added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant