GithubHelp home page GithubHelp logo

descope / nextjs-hackathon-template Goto Github PK

View Code? Open in Web Editor NEW
32.0 10.0 2.0 16.71 MB

Next.js Template using NextAuth and Descope for authentication

Home Page: https://nextjs-hackathon-template.descope.com/

License: MIT License

TypeScript 95.59% CSS 2.43% JavaScript 1.98%
descope hackathon next nextauth nextjs authjs

nextjs-hackathon-template's Introduction

Next.js Hackathon Template

🪐 The Hackathon template comes with the following full-stack features:

  • Descope NextAuth authentication 🔐
  • Protected pages & API routes with NextAuth.
  • The latest Next.js app router, server & client components.
  • Fully customizable Home screen which features an About, Speakers, Sponsors, and FAQ section.
  • A dedicated Team page to showcase all contributors.
  • A Dashboard page for Hackers to complete onboarding forms, acceptance status, and hackathon announcements.
  • Airtable backend for hackers to signup and view hackathon details.
  • Fully responsive UI (mobile, tablet, computer).

✨ Made with...

⚙️ Setup: Local Testing

  1. In the root directory of the project, copy the .env.example to .env by running cp .env.example .env and include the following:
NEXTAUTH_SECRET="YOUR_NEXTAUTH_SECRET"
NEXTAUTH_URL="WHERE SERVER IS HOSTED (e.g. http://localhost:3000)"

DESCOPE_PROJECT_ID="YOUR_DESCOPE_PROJECT_ID"
DESCOPE_ACCESS_KEY="YOUR_DESCOPE_ACCESS_KEY"
NEXT_PRIVATE_SECRET_TOKEN="YOUR_SECRET_TOKEN"
  • DESCOPE_PROJECT_ID - can be found in your Descope's account under the Project page
  • DESCOPE_ACCESS_KEY - can be generated in your Descope's account under the Access Keys page
  • NEXTAUTH_SECRET and NEXT_PRIVATE_SECRET_TOKEN can be generated by the following command in your terminal (do not use the same generated value for both):
$ openssl rand -base64 32

NOTE: The NEXT_PRIVATE_SECRET_TOKEN is used to authenticate the request in the API. It is passed as a parameter in the fetch URL.

  1. Setup SSO
  • To enable SSO and add Descope as an Identity Provider (IdP), we need to add our flow hosting URL:
https://auth.descope.io/<YOUR_DESCOPE_PROJECT_ID>
  • Navigate to Descope Project --> Authentication methods --> Identity Provider:

  1. Installation
  • npm install
  • npm run dev
  • Open http://localhost:3000 in your browser

🔑 Descope

To use Descope, we can implement a custom provider.

Out NextAuth options can be found in /app/_utils/options.ts.

In our authOptions we have our custom Descope provider we have attributes such as your clientID (Descope project id), clientSecret (Descope access key), and wellKnown set to Descope's OpenID Connect configuration which contains our authorization endpoints and authentication data.

import { NextAuthOptions } from "next-auth"


export const authOptions: NextAuthOptions = {
  providers: [
    {
      id: "descope",
      name: "Descope",
      type: "oauth",
      wellKnown: `https://api.descope.com/${process.env.DESCOPE_PROJECT_ID}/.well-known/openid-configuration`,
      authorization: {
        params: { scope: "openid email profile descope.custom_claims" },
      },
      idToken: true,
      clientId: process.env.DESCOPE_PROJECT_ID,
      clientSecret: process.env.DESCOPE_ACCESS_KEY,
      checks: ["pkce", "state"],
      profile(profile, tokens) {
        return {
          id: profile.sub,
          name: profile.name,
          email: profile.email,
          image: profile.picture,
          idToken: tokens.id_token,
          ...tokens,
        };
      },
    },
  ],
  callbacks: {
    async jwt({ token, account }) {
      if (account?.id_token) {
        token.idToken = account.id_token;
      }
      return token;
    },
    async session({ session, token, user }) {
      // @ts-ignore
      session.idToken = token.idToken;
      return session;
    },
  },
}

Note: The purpose of the callbacks at the end, are to be able to fetch the id_token and include it in the NextAuth Session object. You will be able to access custom_claims also through this id_token using getSession() on the client side.

Then in our /app/api/auth/[...nextauth]/route.ts we pass our authOptions and intialize NextAuth.

import NextAuth from "next-auth/next";
import { authOptions } from "../../../_utils/options";


const handler = NextAuth(authOptions)


export { handler as GET, handler as POST }

👾 Template Data

The template data can be found in the ./app/_template_data

All the template data can be customized and found in the following files.

To see our template data in action make your way to app/page.tsx.
In the page.tsx we import the different template data and the components from our _components folder. We pass in our template data into these components as props that then render the data!

📦 Airtable Setup

NOTE: This step is Optional!

To learn more about creating a form and setting up Airtable as a database go to Airtable.md!

🚀 Deploy

Deploy with Vercel

nextjs-hackathon-template's People

Contributors

allenzhou101 avatar descope[bot] avatar dorsha avatar eric-prog avatar gaokevin1 avatar gshriki avatar omercnet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nextjs-hackathon-template's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (local>descope/renovate-config)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

Renovate tried to run on this repository, but found these problems.

  • WARN: Updating multiple npm lock files is deprecated and support will be removed in future versions.

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • Update dependency @types/node to v20.12.8
  • Update dependency eslint to v9.1.1
  • Update dependency eslint-config-next to v14.2.3

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @types/node 20.12.7
  • @types/node-fetch 2.6.11
  • @types/react 18.2.75
  • @types/react-dom 18.2.24
  • airtable 0.12.2
  • autoprefixer 10.4.19
  • encoding 0.1.13
  • flowbite 1.8.1
  • next ^14.1.0
  • next-auth 4.24.7
  • postcss 8.4.38
  • react 18.2.0
  • react-dom 18.2.0
  • tailwindcss 3.4.3
  • typescript 5.4.5
  • eslint 9.0.0
  • eslint-config-next 14.1.4

  • Check this box to trigger a request for Renovate to run again on this repository

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.