Giter VIP home page Giter VIP logo

next-auth-template's Introduction

next-auth-template

This project is a template to help get a GitHub OAuth app quickly up and running with Next.js and Primer.

Getting Started

  1. Create a new repo using this template.

  2. In the root directory, create a new environment file called .env.local.

  3. Navigate to https://github.com/settings/developers and create a new OAuth app.

    • Set the authorization callback URL to http://localhost:3000/api/auth/callback/github.
  4. Add your app's client id and secret and the following variable to your .env.local file:

    GITHUB_APP_CLIENT_ID=xxx
    GITHUB_APP_SECRET=xxx
    NEXTAUTH_SECRET=xxx

    For the NEXTAUTH_SECRET, you can generate a random value in the command line via this openssl command:

    openssl rand -base64 32`
  5. Finally, install all the dependencies, and start running the app.

    npm install
    # then
    npm run dev

    Open http://localhost:3000 in your browser to see the result.

Using the Rest API

Navigate to pages/rest-api.tsx and take a look around. You'll notice that it makes a call const { data } = await octokit?.request("GET /notifications");.

To make this work, you need to have the correct scopes in place. To modify scopes, go to the api/[...nextauth].ts file. You can modify the scopes by changing the scope object here:

 providers: [
    GithubProvider({
      clientId: process.env.GITHUB_APP_CLIENT_ID,
      clientSecret: process.env.GITHUB_APP_SECRET,
      authorization: {
        params: { scope: "read:user user:email notifications public_repo" },
      },
    }),
  ],

List of all available scopes from the GitHub API for OAuth apps: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps

Using GraphQL

Navigate to pages/graphql.tsx a take a look around. You'll notice the following call:

async function getFollowers() {
  const query = `
      query {
        viewer {
          followers(first: 10) {
            nodes {
              name
              login
              avatarUrl
            }
          }
        }
      }
    `;
  const { viewer } = await client?.graphql(query);
}

You can modify the data that is being pulled in by changing this query.

GitHub API GraphQL explorer: https://docs.github.com/en/graphql/overview/explorer

Deployment

Follow Auth.js's deployment documentation to deploy your app via Vercel.

Learn More

Here's a list of resources of the different dependencies used in this project:

next-auth-template's People

Contributors

joeoak avatar tbenning avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.