Giter Club home page Giter Club logo

nextauth-vatsim-connect's Introduction

VATSIM Connect in Next.js 14 and NextAuth

Why

Next.js 14 introduces the new app router feature that breaks most NextAuth implementations. I've done some searching and have moved some files around to get it working again with VATSIM Connect.

Running

This app uses:

  • Next.js 14
  • NextAuth v4
  • Prisma v5
  • MySQL Database (any version that works with Prisma)

If you'd like to use a different database, see Change The Database.

Ensure you have implemented the environment variables in found in .env.example in your own .env file.

Then, simply download and extract wherever you want. With your favorite terminal, navigate to the extracted files and run:

npm i

Then, after ensuring your database is running, run:

npm run dev

This starts a development server. More build/run scripts can be found in package.json.

What Changed?

The [...nextauth].ts file changed so that it exports a handler function. The configuration was moved to ./libs/auth/auth.ts. NextAuth have done some funky magic that detects if NextAuth is being initialised in a Route Handler.

The JSX in ./app/layout.tsx has been wrapped in a custom context that takes the session as a prop. This is because the SessionProvider context cannot be used on a server component (at least, that is what I understood from the errors I was getting). The session is fetched in layout.tsx as it's a server component (doesn't have use client at the top of the page) as to get the session from the client's side, you'd have to make a GET request to /api/auth/session and passed to auth-context.ts, where it provides the session to the rest of the app.

Change The Database

This example uses Prisma. To change the database, follow the instructions from Prisma.

Contributing

I'm very much a self taught web developer. If you see something that isn't quite right, please let me know, or feel free to correct it yourself. I appreciate all feedback!

nextauth-vatsim-connect's People

Contributors

liamdln 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.