#You must provide publicData.userId

1 messages · Page 1 of 1 (latest)

frozen swan
#

I'm trying to change the ctx.session.userId to ctx.session.id. After changing this, I get the error You must provide publicData.userId when trying to login.

The types.ts looks like this

declare module "blitz" {
  export interface Ctx extends DefaultCtx {
    session: SessionContext
  }
  export interface Session {
    isAuthorized: SimpleRolesIsAuthorized<Role>
    PublicData: {
      id: User["id"]
      role: Role
      name: User["name"]
      email: User["email"]
      avatar: User["avatar"]
    }
  }
}

but I can see that the parent PublicData (node_modules/next/dist/shared/lib/utils.d.ts) looks like this;


export declare type PublicData = Session extends {
    PublicData: unknown;
} ? Session['PublicData'] : {
    userId: unknown;
};

Any ideas how I can fix this and use id instead of userId for my session?

Thanks!

pastel inlet
#

I do think you should use userId over id, since Session is also an entity in your database, a session.id would be confusing, and personally session.sessionId is unsightly api...
That said, the session.userId scheme is hardcoded into the blitz-auth package. As seen in the attached:

#

Or in other words: you gotta implement your own session manager if you want to change that api (or maybe use proxy, or shadow id into userId or any other hack)

twin pike
#

Yup what @pastel inlet said. Also are you using the latest version of blitz?

frozen swan
#

Thanks! I'll stick with the userId.