nuxt-oidc-auth icon indicating copy to clipboard operation
nuxt-oidc-auth copied to clipboard

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

Open nathanbrizzee-cdcr opened this issue 1 year ago • 6 comments

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.

https://github.com/itpropro/nuxt-oidc-auth/blob/1c41ec6ace19bef01c023b9a806774fcac420dc1/docs/content/4.composable.md?plain=1#L223

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 avatar Oct 22 '24 03:10 nathanbrizzee-cdcr

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 || "" ));
     }
});

nathanbrizzee-cdcr avatar Oct 22 '24 21:10 nathanbrizzee-cdcr

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

itpropro avatar Oct 24 '24 15:10 itpropro

@itpropro can I ask you an update on this? I'd like to extend the interface but nothing seems to work...

zAlweNy26 avatar Feb 16 '25 17:02 zAlweNy26

Did anybody find a workaround or a solution?

dovca avatar Jul 16 '25 15:07 dovca

@dovca I opened a PR about this if you want to check it out

zAlweNy26 avatar Jul 16 '25 15:07 zAlweNy26

@dovca I opened a PR about this if you want to check it out

Alright, I found a way to make it work as well :D Can't tell whose way is correct, though...

dovca avatar Jul 16 '25 15:07 dovca