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

Extending UserSession interface no longer works with release 1.0.0 beta.2 #78

Open
nathanbrizzee-cdcr opened this issue Oct 22, 2024 · 2 comments

Comments

@nathanbrizzee-cdcr
Copy link

nathanbrizzee-cdcr commented Oct 22, 2024

In version 0.6, I used to be able to extend the UserSession object with my own fields. When I upgraded to version 1.0.0-beta.2, it no longer works even though the documentation says it should. I've tried placing the auth.d.ts file in different places in my Nuxt 3 application. I also tried leaving it in the same place where it used to work. No matter what I do, VSCode no longer recognizes my new fields. I've followed these directions, to no avail. It appears that the change of using the ./types file doesn't propagate the types anymore.

You can extend the type for your provider info by creating a type declaration file (for example, `auth.d.ts`) in your project:

Here's an altered version of my auth.d.ts file. VScode no longer understands these changes.

// auth.d.ts
declare module "#oidc-auth" {
  interface UserSession {
    customInfo?: {
      foo: string;
      bar: string;
    };
  }
}

I'm not sure what else to try.

@nathanbrizzee-cdcr
Copy link
Author

I forgot to mention, in order to properly type function arguments, I had to import UserSession like this.

import type { UserSession } from "nuxt-oidc-auth/runtime/types.d.ts";
import { H3Event } from "h3";
import { setAttributeOnActiveSpan } from "~~/server/tracing.js";

export default defineNitroPlugin(() => {
  sessionHooks.hook("fetch", async (session: UserSession, event: H3Event) => {
     if (session) {
        setAttributeOnActiveSpan("session.userid", String(session.userInfo!.sub || "" ));
        setAttributeOnActiveSpan("session.customInfo.foo", String(session.customInfo!.foo || "" ));
     }
});

@itpropro
Copy link
Owner

The documentation is not yet updated to the current Beta. There will be a updated description soon.

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

2 participants