@neogeek/create-app-oauth-providers

Tests NPM version

Install

$ npm install @neogeek/create-app-oauth-providers

Usage

import { google } from '@neogeek/create-app-oauth-providers';

import {
  GoogleOAuthProfileResponseSchema,
  GoogleOAuthTokenResponseSchema,
} from '@neogeek/create-app-oauth-providers/dist/providers/google';

(async () => {
  const code = req.query.code;

  const tokens = await google.getTokens(code, {
    client_id: process.env.GCP_OAUTH_CLIENT_ID,
    client_secret: process.env.GCP_OAUTH_CLIENT_SECRET,
    redirect_uri: process.env.GCP_OAUTH_REDIRECT_URL,
  });

  const validatedTokens = GoogleOAuthTokenResponseSchema.parse(tokens);

  const profile = await google.getProfile(tokens.access_token);

  const validatedProfile = GoogleOAuthProfileResponseSchema.parse(profile);

  console.log({ tokens, profile });
})();

Types

import type {
  GoogleOAuthProfileResponse,
  GoogleOAuthTokenResponse,
} from '@neogeek/create-app-oauth-providers/dist/providers/google';

Schema (zod validation)

import {
  GoogleOAuthProfileResponseSchema,
  GoogleOAuthTokenResponseSchema,
} from '@neogeek/create-app-oauth-providers/dist/providers/google';