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

Typing for `getRedirectionURL` should allow synchronous methods

Open daedalus28 opened this issue 4 months ago • 1 comments

The typing for getRedirectionURL requires the method to be async, but it doesn't need to be (case in point - one of the official examples defines it synchronously.

When trying to do this in a typescript project, it errors out:

Image

Marking it as async anyway leads to a ts-lint violation for require-await which is part of tslint's recommendedTypeChecked. It's also technically worse for performance because it creates an extra promise (albeit negligible). Right now, it means all users of this library that use typescript with the recommended settings for ts lint have to suppress this with a comment, disable the rule, or add an extraneous code like an extra Promise.resolve. None of these are great options.

I'm not super familiar with this codebase, but after poking around, I think all that's necessary is to change the code here https://github.com/supertokens/supertokens-auth-react/blob/master/lib/ts/recipe/recipeModule/utils.ts#L15

from

getRedirectionURL = async (_: unknown): Promise<string | undefined | null> => undefined;

to

getRedirectionURL = (_: unknown): string | undefined | null | Promise<string | undefined | null> => undefined;

You can also use a utility type like type-fest's Promiseable to make it more concise:

getRedirectionURL = (_: unknown): Promiseable<string | undefined | null> => undefined;

daedalus28 avatar Aug 02 '25 04:08 daedalus28