Skip to content

Size of hashkey has exceeded the maximum size limit of2048 bytes. DynamoDB adapterΒ #5827

@lmillan7

Description

@lmillan7

Question πŸ’¬

I'm implementing the dynamodb adapter (okta as provider) and running local tests I get this error:

adapter_error_getsessionanduser One or more parameter values were invalid: Size of hashkey has exceeded the maximum size limit of2048 bytes

Debugging what is happening I see previous to the error this message:

adapter_getSessionAndUser, metadata: {"args":["eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..fuQGZIkoEiC2kKKA.E2p5CSvyEmhndSGpqPFfv0jn7jirkhv7R5TjVB_8hNxejYi8SuNMIoQmSBdMNxvoygl............................"]}

I use many dots at the end to represent that what is logging is huge 3,921 bytes to be exact, so I guess that's why dynamodb is complaining when trying to make a query with that big value

So, how could I solve this error? I guess if something smaller is provided to dynamodb-adapter should work, but how do I do this and what is the right data or session value to provide to the adapter?

Thank you

How to reproduce β˜•οΈ

This is my code

import { DynamoDB } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import NextAuth, { NextAuthOptions } from 'next-auth';
import { DynamoDBAdapter } from '@next-auth/dynamodb-adapter';
import OktaProvider from 'next-auth/providers/okta';
import { nextAuthPages, nextAuthCallbacks } from '@screentone/addon-auth-wrapper-nextjs/server';
import {
  nextAuthCallbacksOptions,
  oktaProviderOptions,
  oktaValidationConfig,
  adapterOptions,
} from '../../../src/config';

const nextAuthOptions: NextAuthOptions = {
  providers: [OktaProvider(oktaProviderOptions)],
  secret: process.env.NEXT_AUTH_SECRET,
  pages: nextAuthPages,
  callbacks: nextAuthCallbacks(nextAuthCallbacksOptions, 'verbose'),
};

const adapterClient = DynamoDBDocument.from(new DynamoDB(adapterOptions.client), adapterOptions.clientOptions);
nextAuthOptions.adapter = DynamoDBAdapter(adapterClient);

const authOptions = { nextAuthOptions, oktaValidationConfig };

export { authOptions };
export default NextAuth(nextAuthOptions);

Contributing πŸ™ŒπŸ½

Yes, I am willing to help answer this question in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodb@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