Skip to content

feat: ✨ add out-of-the-box support for NextAuth.js #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1109a7d
feat: :sparkles: add out-of-the-box support for NextAuth.js
ericapisani Apr 18, 2022
853a7b3
test: :white_check_mark: add test coverage for the setting of NEXTAUT…
ericapisani Apr 18, 2022
b4713a3
style: disable lint rules for line determining if package is installed
ericapisani Apr 18, 2022
84cebe9
style: lint
ericapisani Apr 18, 2022
01f6b3e
chore: remove unnecessary line in test
ericapisani Apr 18, 2022
fde4fe0
test: need to invoke the 'toBeUndefined' method
ericapisani Apr 18, 2022
ef2830b
Merge branch 'main' into ep/next-auth-support
ericapisani Apr 18, 2022
10b745e
Merge branch 'main' into ep/next-auth-support
ericapisani Apr 19, 2022
781c0e9
Merge branch 'main' into ep/next-auth-support
ericapisani Apr 19, 2022
eceb794
refactor: move logic for setting NEXTAUTH_URL to onBuild step rather …
ericapisani Apr 19, 2022
b3bd617
style: lint
ericapisani Apr 19, 2022
741c189
test: add NextAuth.js demo project for use in testing plugin function…
ericapisani Apr 20, 2022
9cddbaf
chore: add lint file, fix lint issues, and add project to workspace
ericapisani Apr 20, 2022
29c367b
chore: forgot to save the README
ericapisani Apr 20, 2022
79ba32f
style: disable lint rule for existence check of package
ericapisani Apr 20, 2022
7a645f9
style: update lint rules that are being disabled
ericapisani Apr 20, 2022
c5a4999
style: some README changes
ericapisani Apr 20, 2022
0833505
refactor: :recycle: address code review comments
ericapisani Apr 21, 2022
5d16dc9
Merge branch 'main' into ep/next-auth-support
ericapisani Apr 25, 2022
d58129d
chore: rename demo site to follow conventions in project
ericapisani Apr 25, 2022
99dfc1d
style: lint
ericapisani Apr 25, 2022
9bf340c
style: small changes to package.json
ericapisani Apr 25, 2022
e745087
chore: forgot to update the project name in the workspaces entry
ericapisani Apr 25, 2022
397ae1b
style: lint
ericapisani Apr 25, 2022
e567dd2
style: lint
ericapisani Apr 25, 2022
30969a0
style: lint
ericapisani Apr 25, 2022
de39af2
style: lint
ericapisani Apr 25, 2022
98cf62d
chore(deps): add husky and npm-run-all as deps
ericapisani Apr 25, 2022
caeb9d3
chore: add jest deps
ericapisani Apr 25, 2022
2b274f3
chore: more deps
ericapisani Apr 25, 2022
63850e7
chore: remove demo from workspaces
ericapisani Apr 25, 2022
592621a
Merge branch 'main' into ep/next-auth-support
ericapisani Apr 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demos/next-auth/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXTAUTH_URL=http://localhost:3000

NETLIFY_CLIENT_ID=
NETLIFY_CLIENT_SECRET=
4 changes: 4 additions & 0 deletions demos/next-auth/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "next",
"root": true
}
130 changes: 130 additions & 0 deletions demos/next-auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
15 changes: 15 additions & 0 deletions demos/next-auth/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2018-2021, Iain Collins

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 changes: 34 additions & 0 deletions demos/next-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## NextAuth.js Example

This example project came from [next-auth-example](https://github.com/nextauthjs/next-auth-example) provided by the NextAuth.js and was modified to use Netlify as the authentication provider as an example.

For more details on how to get set up and configured with various providers, visit the link above.

### Running locally

Within this project directory:

```
npm install
npm run dev
```

### Configuring your local environment

Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):

```
cp .env.local.example .env.local
```

Add details for the [Netlify Provider](https://next-auth.js.org/providers/netlify), which will require create a Netlify OAuth application.

To create a Netlify OAuth application:
* Visit `https://app.netlify.com/user/applications`
* Click 'New OAuth App'
* Enter an application name
* Enter a redirect URI (for the purposes of this demo application you would use `http://localhost:3000/api/auth/callback/netlify`)
* Save the application, and copy the value for 'Client ID' as the `NETLIFY_CLIENT_ID` and the 'Client Secret' as the `NETLIFY_CLIENT_SECRET` into your `.env.local` file within the project
* If you're testing this on a deployed Netlify site you'll need to set the environment variables as part of the `Site Settings > Build & Deploy > Environment` settings. You'll also need to generate a `NEXTAUTH_SECRET` environment variable and set that for a production build.

For configuring additional authentication providers, see the original documentation [here](https://github.com/nextauthjs/next-auth-example#3-configure-authentication-providers)
20 changes: 20 additions & 0 deletions demos/next-auth/components/access-denied.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { signIn } from "next-auth/react"

export default function AccessDenied() {
return (
<>
<h1>Access Denied</h1>
<p>
<a
href="/api/auth/signin"
onClick={(e) => {
e.preventDefault()
signIn()
}}
>
You must be signed in to view this page
</a>
</p>
</>
)
}
14 changes: 14 additions & 0 deletions demos/next-auth/components/footer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.footer {
margin-top: 2rem;
}

.navItems {
margin-bottom: 1rem;
padding: 0;
list-style: none;
}

.navItem {
display: inline-block;
margin-right: 1rem;
}
30 changes: 30 additions & 0 deletions demos/next-auth/components/footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Link from "next/link"
import styles from "./footer.module.css"
import packageJSON from "../package.json"

export default function Footer() {
return (
<footer className={styles.footer}>
<hr />
<ul className={styles.navItems}>
<li className={styles.navItem}>
<a href="https://next-auth.js.org">Documentation</a>
</li>
<li className={styles.navItem}>
<a href="https://www.npmjs.com/package/next-auth">NPM</a>
</li>
<li className={styles.navItem}>
<a href="https://github.com/nextauthjs/next-auth-example">GitHub</a>
</li>
<li className={styles.navItem}>
<Link href="/policy">
<a>Policy</a>
</Link>
</li>
<li className={styles.navItem}>
<em>next-auth@{packageJSON.dependencies["next-auth"]}</em>
</li>
</ul>
</footer>
)
}
92 changes: 92 additions & 0 deletions demos/next-auth/components/header.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Set min-height to avoid page reflow while session loading */
.signedInStatus {
display: block;
min-height: 4rem;
width: 100%;
}

.loading,
.loaded {
position: relative;
top: 0;
opacity: 1;
overflow: hidden;
border-radius: 0 0 0.6rem 0.6rem;
padding: 0.6rem 1rem;
margin: 0;
background-color: rgba(0, 0, 0, 0.05);
transition: all 0.2s ease-in;
}

.loading {
top: -2rem;
opacity: 0;
}

.signedInText,
.notSignedInText {
position: absolute;
padding-top: 0.8rem;
left: 1rem;
right: 6.5rem;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inherit;
z-index: 1;
line-height: 1.3rem;
}

.signedInText {
padding-top: 0rem;
left: 4.6rem;
}

.avatar {
border-radius: 2rem;
float: left;
height: 2.8rem;
width: 2.8rem;
background-color: white;
background-size: cover;
background-repeat: no-repeat;
}

.button,
.buttonPrimary {
float: right;
margin-right: -0.4rem;
font-weight: 500;
border-radius: 0.3rem;
cursor: pointer;
font-size: 1rem;
line-height: 1.4rem;
padding: 0.7rem 0.8rem;
position: relative;
z-index: 10;
background-color: transparent;
color: #555;
}

.buttonPrimary {
background-color: #346df1;
border-color: #346df1;
color: #fff;
text-decoration: none;
padding: 0.7rem 1.4rem;
}

.buttonPrimary:hover {
box-shadow: inset 0 0 5rem rgba(0, 0, 0, 0.2);
}

.navItems {
margin-bottom: 2rem;
padding: 0;
list-style: none;
}

.navItem {
display: inline-block;
margin-right: 1rem;
}
Loading