npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@openlab/vercel-netlify-cms-github

v1.1.1

Published

Vercel API routes to login to netlify-cms deployed on vercel

Downloads

333

Readme

vercel-netlify-cms-github

An NPM package to allow you to use netlify-cms with GitHub authentication when deploying on Vercel.

Installation

1. Install the module

# cd into/your/vercel/project
npm install @openlab/vercel-netlify-cms-github

2. Create the auth route

Create a vercel endpoint at api/auth.ts

export { auth as default } from '@openlab/vercel-netlify-cms-github'

3. Create the callback route

Create a vercel endpoint at api/callback.ts

export { callback as default } from '@openlab/vercel-netlify-cms-github'

4. Update your config.yml

Update your config.yml to include this backend

backend:
  name: github
  repo: YOUR_GITHUB_REPO
  base_url: YOUR_WEBSITE
  auth_endpoint: api/auth
  • repo should be your GitHub repo path, like owner/repo
  • base_url should be the full url to the root of your site, like https://example.com/
  • auth_endpoint needs to be set to link it up correctly, you can't put it in base_url

(optional) Configure vercel.json

If you have your admin files in a folder (e.g. admin/index.html and admin/config.yml) you might want to force vercel to use trailing slashes. This is because if you visit /admin netlify will look for a config at /config.yml, not in the admin folder.

To solve this add (or update) your vercel.json in the project root:

{
  "trailingSlash": true
}

5. Commit these endpoints to git

git add api/auth.ts api/callback.ts
git commit -m ":star: add GitHub auth routes and connect to netlify-cms"

6. Create a GitHub OAuth application

Go to https://github.com/settings/developers.

  • Set Homepage URL to your site's homepage
  • Set Authorization callback URL to `https://YOUR_SITE_HERE/api/callback
  • Make a note of your client_id and client_secret

7. Setup Vercel environment variables

Go to your vercel dashboard, https://vercel.com.

  • Navigate to your project then Settings > Environment Variables
  • Add OAUTH_CLIENT_ID and set the value from the GitHub OAuth application
  • Add OAUTH_CLIENT_SECRET and set the value from the GitHub OAuth application
  • You can store them however you like but secrets should be the most secure
  • Make sure your environment variables are exposed on the deployment(s) you need

Done

🎉 Your site should now be linked up!

Configuration

Environment Variables

In addition to OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET, this package also exposes these variables to configure the GitHub authentication. These all have default values configured to talk to github.com.

  • OAUTH_HOST (default: https://github.com) The GitHub server to talk to
  • OAUTH_TOKEN_PATH (default: /login/oauth/access_token) The path of the GitHub OAuth token endpoint
  • OAUTH_AUTHORIZE_PATH (default: /login/oauth/authorize) The path of the GitHub OAuth Authorization endpoint

API usage

Other than the Vercel endpoints, these are exported:

  • oauthConfig is an object with configuration for simple-oauth2
  • randomState is a function to generate a random state for an OAuth2 flow
  • renderResponse is a function to generate HTML with client-side JavaScript to complete the OAuth2 flow using window.opener.postMessage

These were primarily exposed for digitalinteraction/netlify-cms-github-auth to use.


This project was set up by puggle