Key Features:
- ๐ Next-auth v5 (Auth.js)
- ๐ Next.js 14 with server actions
- ๐ Credentials Provider
- ๐ OAuth Provider (Social login with Google & GitHub)
- ๐ Forgot password functionality
- โ๏ธ Email verification
- ๐ฑ Two factor verification
- ๐ฅ User roles (Admin & User)
- ๐ Login component (Opens in redirect or modal)
- ๐ Register component
- ๐ค Forgot password component
- โ Verification component
โ ๏ธ Error component- ๐ Login button
- ๐ช Logout button
- ๐ง Role Gate
- ๐ Exploring next.js middleware
- ๐ Extending & Exploring next-auth session
- ๐ Exploring next-auth callbacks
- ๐ค useCurrentUser hook
- ๐ useRole hook
- ๐ง currentUser utility
- ๐ฎ currentRole utility
- ๐ฅ๏ธ Example with server component
- ๐ป Example with client component
- ๐ Render content for admins using RoleGate component
- ๐ก๏ธ Protect API Routes for admins only
- ๐ Protect Server Actions for admins only
- ๐ง Change email with new verification in Settings page
- ๐ Change password with old password confirmation in Settings page
- ๐ Enable/disable two-factor auth in Settings page
- ๐ Change user role in Settings page (for development purposes only)
Node version 18.7.x
git clone https://github.com/gauravmandall/fullstack-auth.git
npm i
# or
yarn install
# or
pnpm install
rename .env.example
to .env
and fill in the values
DATABASE_URL=
DIRECT_URL=
AUTH_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
RESEND_API_KEY=
NEXT_PUBLIC_APP_URL="http://localhost:3000" # or your production domain
Resend Api: https://resend.com/api-keys
To obtain these values follow the url
below
variables | url |
---|---|
Database key |
https://console.neon.tech/ |
Github oauth key |
https://github.com/settings/applications/new |
Google api key |
https://console.cloud.google.com/apis/credentials/ |
Resend api key |
https://resend.com/api-keys |
npx prisma generate
npx prisma db push
to clean prisma db
npx prisma migrate reset # danger zone
npm run dev
# or
yarn dev
# or
pnpm dev
Running commands with npm npm run [command]
command | description |
---|---|
dev |
Starts a development instance of the app |
Contributions are always welcome!
See contributing.md
for ways to get started.
Please adhere to this project's code of conduct
.
If you have any feedback, please reach out to us at contact.gauravmandall@gmail.com
Give a Star โญ to support my projects.
MIT License
Copyright (c) 2024 Gaurav Mandal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.