supertokens-auth-react icon indicating copy to clipboard operation
supertokens-auth-react copied to clipboard

Define a type for getAccessTokenPayloadSecurely in Session

Open guillempuche opened this issue 1 year ago • 0 comments

any type in getAccessTokenPayloadSecurely isn't not helping making our code cleanr. Docs https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/claims/access-token-payload#reading-the-payload-on-the-frontend says it can return an object.

import Session from 'supertokens-web-js/recipe/session';

async function someFunc() {
      if (await Session.doesSessionExist()) {
            let accessTokenPayload = await Session.getAccessTokenPayloadSecurely();
            let customClaimValue = accessTokenPayload.customClaim
      }
}

// supertokens-auth-react/recipe/session/index.d.ts

    static getAccessToken(input?: { userContext?: UserContext }): Promise<string | undefined>;
    static getAccessTokenPayloadSecurely(input?: { userContext?: UserContext }): Promise<any>;

Could you replace any for something like type | undefined to improve cases like mine:

import { Data, type Either, type Option } from 'effect'

export type Listener = {
	initialized: () => void
	sessionUpdated: (
		session: Either.Either<
			Option.Option<SessionPayload>,
			ErrorAbc
		>,
	) => void
}

guillempuche avatar Nov 08 '24 21:11 guillempuche