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

Module augmentation #82

Open
lokimckay opened this issue Aug 25, 2024 · 0 comments
Open

Module augmentation #82

lokimckay opened this issue Aug 25, 2024 · 0 comments

Comments

@lokimckay
Copy link

Is it possible to include arbitrary fields in the user interface as documented here?
https://authjs.dev/getting-started/typescript#module-augmentation

My attempt:

env.d.ts

declare module "auth-astro" {
  interface User {
    id: string;
    myField: string;
  }
}

auth.config.ts

return defineConfig({
    ...
    callbacks: {
      async jwt({ token, user }) {
        if (user) {
          token.id = user.id;
          token.myField = "foo";
        }
        return token;
      },
      session({ session, token }) {
        session.user.id = token.id as string;
        session.user.myField = token.myField as string; // typescript says: "Property 'myField' does not exist on type 'AdapterUser & User'"
        return session;
      },
    },
  });

Typescript throws the type error:
Property 'myField' does not exist on type 'AdapterUser & User'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant