Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix object lint errors, output ESM + CJS #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

psibean
Copy link

@psibean psibean commented Feb 12, 2022

This isn't a necessary or a required change, I did it more out of interest as I had initially implemented my own discord oauth2 passport strategy prior to finding this repo.

cjs output goes to dist/cjs, esm output goes to dist/esm, type output goes into dist and is done independently of the builds via it's own build:types script.

  34:31  error  Don't use `object` as a type. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).
Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys                                                                                         @typescript-eslint/ban-types       34:31  error  Don't use `object` as a type. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).
Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys                                                                                         @typescript-eslint/ban-types     
  34:47  error  Don't use `object` as a type. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys    

These lint errors were present, so I replaced all object type uses as recommended.

I've tested these changes using npm pack and installing the local file on a live application with the following configuration:

The DiscordUserProfile type below is my own which extends the included Profile type (covers the identify scope).

new Strategy({
  clientID: DISCORD_CLIENT_ID,
  clientSecret: DISCORD_CLIENT_SECRET,
  state: true,
  pkce: true,
  scope: ['identify', 'email'],
  passReqToCallback: true,
},
  async (req: Request, accessToken: string, refreshToken: string, profile: DiscordUserProfile, cb: any) => {
    const userSelect = {
      user: {
        select: {
          id: true,
          email: true,
        }
      }
    };
    const existingProvider = await prisma.authProvider.findFirst({
      where: {
        providerUserId: profile.id,
        name: 'discord'
      },
      include: userSelect
    });

    if (existingProvider === null) {
      const existingUser = await prisma.user.findUnique({
        where: { email: profile.email },
        select: userSelect.user.select,
      });
      if (existingUser === null) {
        if (!profile.verified) {
          cb({ error: "Your Discord email must be verified to use it as a sign in option." }, null)
        }

        const newProvider = await prisma.authProvider.create({
          data: {
            name: 'discord',
            providerUserId: profile.id,
            user: {
              create: {
                email: profile.email
              },
            }
          },
          include: userSelect
        })
        cb(null, newProvider.user);
      } else {
        await prisma.authProvider.create({
          data: {
            name: 'discord',
            providerUserId: profile.id,
            user: {
              connect: {
                email: profile.email
              }
            }
          }
        })
        cb(null, existingUser);
      }
    } else  {
      cb(null, existingProvider.user);
    }
  });

Take it or leave it, the changes are here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant