supertokens-website icon indicating copy to clipboard operation
supertokens-website copied to clipboard

Support Module Augmentation in TypeScript

Open nip10 opened this issue 2 years ago • 0 comments

This is a feature request for module augmentation using TypeScript.

When you add custom properties to the access token payload in the backend via createNewSession override, you lose type safety in the front-end when accessing the payload object.

A sortof work-around is to do something like

interface AccessTokenPayload {
  extraProperty: string
}

const accessTokenPayload: AccessTokenPayload = await session.getAccessTokenPayloadSecurely()

It would be nice to have a way to tell TypeScript the content of the payload in a more global way, like next-auth does

import { AccessTokenPayload } from "super-tokens/foo/bar"

declare module "super-tokens/foo/bar" {
  interface AccessTokenPayload {
    address?: string;
	postalCode: number;
  }
}

nip10 avatar Mar 31 '23 11:03 nip10