This project is an example of how to implement authentication in a web application using NextAuth.js and the GitHub authentication strategy.
- Login with your GitHub account.
- Access to public GitHub profile data post-authentication.
- Basic application structure using React.
- Node.js and npm installed on your machine.
-
Clone this repository on your local machine:
git clone git@github.com:eduveliz/auth-next-github.git cd auth-next-github
-
Install the dependencies:
npm install
-
Create a GitHub Application:
- Visit GitHub Developer Settings and create a new application.
- Set the authorization callback URL as
http://localhost:3000/api/auth/callback/github
. - Once the application is created, obtain the Client ID and Client Secret.
-
Configure environment variables:
- Create a
.env.local
file in the project root. - Add the following variables with your GitHub application values:
NEXT_AUTH_SECRET=Generate ussing openssl rand -base64 32 on console GITHUB_CLIENT_ID=YOUR_CLIENT_ID GITHUB_CLIENT_SECRET=YOUR_CLIENT_SECRET
- Create a
-
Run the application:
npm run dev
The application should be accessible at
http://localhost:3000
.
Contributions are welcome! If you find issues or improvements, feel free to open an issue or submit a pull request.
This project is under the MIT License.