sergiodxa / remix-auth

Simple Authentication for Remix
https://sergiodxa.github.io/remix-auth/
MIT License
2k stars 110 forks source link

`User` is serialized but the type doesn't express that #273

Open lifeiscontent opened 7 months ago

lifeiscontent commented 7 months ago

Describe the bug

when using methods like isAuthenticated it doesn't return a User but rather a SerializeFrom<User> e.g. if you try to return a record with a bigint it'll serialize to a string

I'm not sure if this has something to do with how the cookie storage works or if this is a bug in remix-auth but just ran into this issue where the verify function return value was complaining that the type of user had string values but prisma was returning bigint

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

type User = {
  id: string
}

function getUser(): {id: bigint } {
  return {id: new BigInt(1) }
}

export const authenticator = new Authenticator<User>(sessionStorage);

assert(process.env.GOOGLE_CLIENT_ID, 'GOOGLE_CLIENT_ID is not set');
assert(process.env.GOOGLE_CLIENT_SECRET, 'GOOGLE_CLIENT_SECRET is not set');

authenticator.use(
  new GoogleOAuth2Strategy(
    {
      callbackURL: `/auth/google/callback`,
      clientID: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      responseType: 'code',
      accessType: 'offline',
      scope:
        'openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
    },
    async ({ profile }) => {
       return getUser() // this complains because it returns bigints rather than string
                                   // but the return value will always be strings during consumption in loaders/actions
    },
  ),
  'google',
);

Expected behavior

proper type handling

Screenshots or Videos

No response

Platform

Additional context

No response