dealwith / nextjs-steam-auth

An example NextJS application that configures Passport-based Steam authentication via Next Connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NextJS Steam Authentication

πŸ“– Table of Contents

πŸ‘‹ Introduction

NextJS is a React-based web framework that aims to deliver websites as statically as possible. This can provide many performance and development benefits over a framework like Express.

Setting up authentication can be tricky, especially with OpenID login systems such as Steam. This repository is an example of how one may go about injecting Steam user authentication into their React-based application and are looking to migrate to a framework like NextJS.

πŸ”Œ Getting Started

After downloading the project, you should install all of the required dependencies.

$ npm install

Fill in a .env file with the following keys filled, much like .env.sample

DOMAIN=http://localhost:3000 # Where this app will run
SESSION_SECRET=ABCD # 32+ char random string
STEAM_API_KEY= # Your Steam API Key

You can run the web application in development mode.

$ npm run dev

You can also test the web application for production if you feel the need.

$ npm run build
$ npm start

βš™οΈ How It Works

🚧 TODO 🚧

πŸ’‘ Improvements To Make

This is only one example of authenticating a user with their Steam account via NextJS. There are some fixes that can be added to better development and cleanliness without making significant changes.

Isolating Middleware

path is set within login.ts, logout.ts and return.ts or the middleware will apply to all routes. An alternative solution will need to ensure that middleware set on an API route only runs on that API route. Removing path from each route handler will cause constantly redirect you back to Steam's login page.

Avoiding Manual Request Population

router works in parallel with NextJS's native router. However, it needs to be explicitly activated per React page, as seen in Index.getServerSideProps where it will populate the Request object with any additional fields picked up. This can be repetitive in nature so having router run natively or just once for all pages would be ideal.

πŸ“š Helpful Resources

About

An example NextJS application that configures Passport-based Steam authentication via Next Connect

License:MIT License


Languages

Language:TypeScript 93.8%Language:JavaScript 6.2%