Skip to content

Commit eb36662

Browse files
committed
🔄 Synced local '.' with remote 'apps/examples/nextjs-pages'
1 parent 22ef58e commit eb36662

37 files changed

+1603
-1
lines changed

‎.env.local.example

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
AUTH_SECRET= # Linux: `openssl rand -hex 32` or go to https://generate-secret.vercel.app/32
2+
3+
AUTH_AUTH0_ID=
4+
AUTH_AUTH0_SECRET=
5+
AUTH_AUTH0_ISSUER=
6+
7+
AUTH_FACEBOOK_ID=
8+
AUTH_FACEBOOK_SECRET=
9+
10+
AUTH_GITHUB_ID=
11+
AUTH_GITHUB_SECRET=
12+
13+
AUTH_GOOGLE_ID=
14+
AUTH_GOOGLE_SECRET=
15+
16+
AUTH_TWITTER_ID=
17+
AUTH_TWITTER_SECRET=

‎.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
3+
node_modules/
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
.yarn-integrity
11+
.npm
12+
13+
.eslintcache
14+
15+
*.tsbuildinfo
16+
next-env.d.ts
17+
18+
.next
19+
.vercel
20+
.env*.local

‎README.md

+112-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,112 @@
1-
T
1+
> The example repository is maintained from a [monorepo](https://github.com/nextauthjs/next-auth/tree/main/apps/examples/nextjs). Pull Requests should be opened against [`nextauthjs/next-auth`](https://github.com/nextauthjs/next-auth).
2+
3+
<p align="center">
4+
<br/>
5+
<a href="https://authjs.dev" target="_blank"><img width="150px" src="https://authjs.dev/img/logo/logo-sm.png" /></a>
6+
<h3 align="center">NextAuth.js Example App</h3>
7+
<p align="center">
8+
Open Source. Full Stack. Own Your Data.
9+
</p>
10+
<p align="center" style="align: center;">
11+
<a href="https://npm.im/next-auth">
12+
<img alt="npm" src="https://img.shields.io/npm/v/next-auth?color=green&label=next-auth">
13+
</a>
14+
<a href="https://bundlephobia.com/result?p=next-auth-example">
15+
<img src="https://img.shields.io/bundlephobia/minzip/next-auth?label=next-auth" alt="Bundle Size"/>
16+
</a>
17+
<a href="https://www.npmtrends.com/next-auth">
18+
<img src="https://img.shields.io/npm/dm/next-auth?label=next-auth%20downloads" alt="Downloads" />
19+
</a>
20+
<a href="https://npm.im/next-auth">
21+
<img src="https://img.shields.io/badge/npm-TypeScript-blue" alt="TypeScript" />
22+
</a>
23+
</p>
24+
</p>
25+
26+
## Overview
27+
28+
NextAuth.js is a complete open source authentication solution.
29+
30+
This is an example application that shows how `next-auth` is applied to a basic Next.js app.
31+
32+
The deployed version can be found at [`next-auth-example.vercel.app`](https://next-auth-example.vercel.app)
33+
34+
### About NextAuth.js
35+
36+
NextAuth.js is an easy to implement, full-stack (client/server) open source authentication library originally designed for [Next.js](https://nextjs.org) and [Serverless](https://vercel.com). Our goal is to [support even more frameworks](https://github.com/nextauthjs/next-auth/issues/2294) in the future.
37+
38+
Go to [next-auth.js.org](https://authjs.dev) for more information and documentation.
39+
40+
> _NextAuth.js is not officially associated with Vercel or Next.js._
41+
42+
## Getting Started
43+
44+
### 1. Clone the repository and install dependencies
45+
46+
```
47+
git clone https://github.com/nextauthjs/next-auth-example.git
48+
cd next-auth-example
49+
npm install
50+
```
51+
52+
### 2. Configure your local environment
53+
54+
Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):
55+
56+
```
57+
cp .env.local.example .env.local
58+
```
59+
60+
Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc).
61+
62+
#### Database
63+
64+
A database is needed to persist user accounts and to support email sign in. However, you can still use NextAuth.js for authentication without a database by using OAuth for authentication. If you do not specify a database, [JSON Web Tokens](https://jwt.io/introduction) will be enabled by default.
65+
66+
You **can** skip configuring a database and come back to it later if you want.
67+
68+
For more information about setting up a database, please check out the following links:
69+
70+
- Docs: [authjs.dev/reference/core/adapters](https://authjs.dev/reference/core/adapters)
71+
72+
### 3. Configure Authentication Providers
73+
74+
1. Review and update options in `auth.ts` as needed.
75+
76+
2. When setting up OAuth, in the developer admin page for each of your OAuth services, you should configure the callback URL to use a callback path of `{server}/api/auth/callback/{provider}`.
77+
78+
e.g. For Google OAuth you would use: `http://localhost:3000/api/auth/callback/google`
79+
80+
A list of configured providers and their callback URLs is available from the endpoint `api/auth/providers`. You can find more information at https://authjs.dev/getting-started/providers/oauth-tutorial
81+
82+
1. You can also choose to specify an SMTP server for passwordless sign in via email.
83+
84+
### 4. Start the application
85+
86+
To run your site locally, use:
87+
88+
```
89+
npm run dev
90+
```
91+
92+
To run it in production mode, use:
93+
94+
```
95+
npm run build
96+
npm run start
97+
```
98+
99+
### 5. Preparing for Production
100+
101+
Follow the [Deployment documentation](https://authjs.dev/getting-started/deployment)
102+
103+
## Acknowledgements
104+
105+
<a href="https://vercel.com?utm_source=nextauthjs&utm_campaign=oss">
106+
<img width="170px" src="https://raw.githubusercontent.com/nextauthjs/next-auth/main/docs/static/img/powered-by-vercel.svg" alt="Powered By Vercel" />
107+
</a>
108+
<p align="left">Thanks to Vercel sponsoring this project by allowing it to be deployed for free for the entire NextAuth.js Team</p>
109+
110+
## License
111+
112+
ISC
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// import { handlers } from "../../../auth"
2+
// const { GET, POST } = handlers
3+
//
4+
// const handler = async (req, res) => {
5+
// const { method, headers, query, body } = req
6+
// const webRequest = {
7+
// ...req,
8+
// headers: new Headers(req.headers),
9+
// url: new URL(`http://${req.headers["x-forwarded-host"]}${req.url}`),
10+
// }
11+
//
12+
// switch (method) {
13+
// case "GET":
14+
// res.send(GET(webRequest))
15+
// break
16+
// case "POST":
17+
// res.send(POST(webRequest))
18+
// break
19+
// }
20+
// }
21+
//
22+
// export default handler
23+
24+
import { handlers } from "auth"
25+
export const { GET, POST } = handlers

‎auth.ts

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import NextAuth from "next-auth"
2+
3+
// import Apple from "next-auth/providers/apple"
4+
// import Atlassian from "next-auth/providers/atlassian"
5+
// import Auth0 from "next-auth/providers/auth0"
6+
// import Authentik from "next-auth/providers/authentik"
7+
// import AzureAD from "next-auth/providers/azure-ad"
8+
// import AzureB2C from "next-auth/providers/azure-ad-b2c"
9+
// import Battlenet from "next-auth/providers/battlenet"
10+
// import Box from "next-auth/providers/box"
11+
// import BoxyHQSAML from "next-auth/providers/boxyhq-saml"
12+
// import Bungie from "next-auth/providers/bungie"
13+
// import Cognito from "next-auth/providers/cognito"
14+
// import Coinbase from "next-auth/providers/coinbase"
15+
// import Discord from "next-auth/providers/discord"
16+
// import Dropbox from "next-auth/providers/dropbox"
17+
// import DuendeIDS6 from "next-auth/providers/duende-identity-server6"
18+
// import Eveonline from "next-auth/providers/eveonline"
19+
// import Facebook from "next-auth/providers/facebook"
20+
// import Faceit from "next-auth/providers/faceit"
21+
// import FortyTwoSchool from "next-auth/providers/42-school"
22+
// import Foursquare from "next-auth/providers/foursquare"
23+
// import Freshbooks from "next-auth/providers/freshbooks"
24+
// import Fusionauth from "next-auth/providers/fusionauth"
25+
import GitHub from "next-auth/providers/github"
26+
// import Gitlab from "next-auth/providers/gitlab"
27+
// import Google from "next-auth/providers/google"
28+
// import Hubspot from "next-auth/providers/hubspot"
29+
// import Instagram from "next-auth/providers/instagram"
30+
// import Kakao from "next-auth/providers/kakao"
31+
// import Keycloak from "next-auth/providers/keycloak"
32+
// import Line from "next-auth/providers/line"
33+
// import LinkedIn from "next-auth/providers/linkedin"
34+
// import Mailchimp from "next-auth/providers/mailchimp"
35+
// import Mailru from "next-auth/providers/mailru"
36+
// import Medium from "next-auth/providers/medium"
37+
// import Naver from "next-auth/providers/naver"
38+
// import Netlify from "next-auth/providers/netlify"
39+
// import Okta from "next-auth/providers/okta"
40+
// import Onelogin from "next-auth/providers/onelogin"
41+
// import Osso from "next-auth/providers/osso"
42+
// import Osu from "next-auth/providers/osu"
43+
// import Passage from "next-auth/providers/passage"
44+
// import Patreon from "next-auth/providers/patreon"
45+
// import Pinterest from "next-auth/providers/pinterest"
46+
// import Pipedrive from "next-auth/providers/pipedrive"
47+
// import Reddit from "next-auth/providers/reddit"
48+
// import Salesforce from "next-auth/providers/salesforce"
49+
// import Slack from "next-auth/providers/slack"
50+
// import Spotify from "next-auth/providers/spotify"
51+
// import Strava from "next-auth/providers/strava"
52+
// import Todoist from "next-auth/providers/todoist"
53+
// import Trakt from "next-auth/providers/trakt"
54+
// import Twitch from "next-auth/providers/twitch"
55+
// import Twitter from "next-auth/providers/twitter"
56+
// import UnitedEffects from "next-auth/providers/united-effects"
57+
// import Vk from "next-auth/providers/vk"
58+
// import Wikimedia from "next-auth/providers/wikimedia"
59+
// import Wordpress from "next-auth/providers/wordpress"
60+
// import WorkOS from "next-auth/providers/workos"
61+
// import Yandex from "next-auth/providers/yandex"
62+
// import Zitadel from "next-auth/providers/zitadel"
63+
// import Zoho from "next-auth/providers/zoho"
64+
// import Zoom from "next-auth/providers/zoom"
65+
66+
import type { NextAuthConfig } from "next-auth"
67+
68+
export const config = {
69+
theme: {
70+
logo: "https://next-auth.js.org/img/logo/logo-sm.png",
71+
},
72+
providers: [
73+
// Apple,
74+
// Atlassian,
75+
// Auth0,
76+
// Authentik,
77+
// AzureAD,
78+
// AzureB2C,
79+
// Battlenet,
80+
// Box,
81+
// BoxyHQSAML,
82+
// Bungie,
83+
// Cognito,
84+
// Coinbase,
85+
// Discord,
86+
// Dropbox,
87+
// DuendeIDS6,
88+
// Eveonline,
89+
// Facebook,
90+
// Faceit,
91+
// FortyTwoSchool,
92+
// Foursquare,
93+
// Freshbooks,
94+
// Fusionauth,
95+
GitHub,
96+
// Gitlab,
97+
// Google,
98+
// Hubspot,
99+
// Instagram,
100+
// Kakao,
101+
// Keycloak,
102+
// Line,
103+
// LinkedIn,
104+
// Mailchimp,
105+
// Mailru,
106+
// Medium,
107+
// Naver,
108+
// Netlify,
109+
// Okta,
110+
// Onelogin,
111+
// Osso,
112+
// Osu,
113+
// Passage,
114+
// Patreon,
115+
// Pinterest,
116+
// Pipedrive,
117+
// Reddit,
118+
// Salesforce,
119+
// Slack,
120+
// Spotify,
121+
// Strava,
122+
// Todoist,
123+
// Trakt,
124+
// Twitch,
125+
// Twitter,
126+
// UnitedEffects,
127+
// Vk,
128+
// Wikimedia,
129+
// Wordpress,
130+
// WorkOS,
131+
// Yandex,
132+
// Zitadel,
133+
// Zoho,
134+
// Zoom,
135+
],
136+
callbacks: {
137+
authorized({ request, auth }) {
138+
const { pathname } = request.nextUrl
139+
if (pathname === "/middleware-example") return !!auth
140+
return true
141+
},
142+
jwt({ token, trigger, session }) {
143+
if (trigger === "update") token.name = session.user.name
144+
return token
145+
},
146+
},
147+
} satisfies NextAuthConfig
148+
149+
export const { handlers, auth, signIn, signOut } = NextAuth(config)

‎components.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "app/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true
11+
},
12+
"aliases": {
13+
"components": "@/components",
14+
"utils": "@/lib/utils"
15+
}
16+
}

‎components/auth-components.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { signIn, signOut } from "next-auth/react"
2+
import { Button } from "./ui/button"
3+
4+
export function SignIn({
5+
provider,
6+
...props
7+
}: { provider?: string } & React.ComponentPropsWithRef<typeof Button>) {
8+
return (
9+
<Button onClick={() => signIn()} {...props}>
10+
Sign In
11+
</Button>
12+
)
13+
}
14+
15+
export function SignOut(props: React.ComponentPropsWithRef<typeof Button>) {
16+
return (
17+
<Button
18+
onClick={() => signOut()}
19+
variant="ghost"
20+
className="p-0 w-full"
21+
{...props}
22+
>
23+
Sign Out
24+
</Button>
25+
)
26+
}

0 commit comments

Comments
 (0)