mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12517f629b | ||
|
|
77012bc00c | ||
|
|
60fdf26a56 | ||
|
|
0fae0c7a8e |
@@ -60,7 +60,7 @@ export default NextAuth({
|
||||
credentials: {
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
async authorize(credentials, req) {
|
||||
if (credentials.password === "password") {
|
||||
return {
|
||||
id: 1,
|
||||
|
||||
@@ -62,8 +62,8 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@next-auth/prisma-legacy-adapter": "canary",
|
||||
"@next-auth/typeorm-legacy-adapter": "canary",
|
||||
"@next-auth/prisma-legacy-adapter": "0.0.1-canary.127",
|
||||
"@next-auth/typeorm-legacy-adapter": "0.0.2-canary.129",
|
||||
"futoin-hkdf": "^1.3.2",
|
||||
"jose": "^1.27.2",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function Twitter(options) {
|
||||
id: profile.id_str,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
image: profile.profile_image_url_https.replace(/_normal\.jpg$/, ".jpg"),
|
||||
image: profile.profile_image_url_https.replace(/_normal\.(jpg|png|gif)$/, ".$1"),
|
||||
}
|
||||
},
|
||||
...options,
|
||||
|
||||
@@ -336,7 +336,7 @@ export default async function callback(req, res) {
|
||||
let userObjectReturnedFromAuthorizeHandler
|
||||
try {
|
||||
userObjectReturnedFromAuthorizeHandler = await provider.authorize(
|
||||
credentials
|
||||
credentials, {...req, options: {}, cookies: {}}
|
||||
)
|
||||
if (!userObjectReturnedFromAuthorizeHandler) {
|
||||
return res
|
||||
|
||||
4
types/providers.d.ts
vendored
4
types/providers.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import { Profile, TokenSet, User } from "."
|
||||
import { Awaitable } from "./internals/utils"
|
||||
import { Awaitable, NextApiRequest } from "./internals/utils"
|
||||
|
||||
export type ProviderType = "oauth" | "email" | "credentials"
|
||||
|
||||
@@ -115,7 +115,7 @@ interface CredentialsConfig<C extends Record<string, CredentialInput> = {}>
|
||||
extends CommonProviderOptions {
|
||||
type: "credentials"
|
||||
credentials: C
|
||||
authorize(credentials: Record<keyof C, string>): Awaitable<User | null>
|
||||
authorize(credentials: Record<keyof C, string>, req: NextApiRequest): Awaitable<User | null>
|
||||
}
|
||||
|
||||
export type CredentialsProvider = (
|
||||
|
||||
@@ -254,12 +254,14 @@ providers: [
|
||||
username: { label: "Username", type: "text", placeholder: "jsmith" },
|
||||
password: { label: "Password", type: "password" }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
const user = (credentials) => {
|
||||
async authorize(credentials, req) {
|
||||
const user = (credentials, req) => {
|
||||
// You need to provide your own logic here that takes the credentials
|
||||
// submitted and returns either a object representing a user or value
|
||||
// that is false/null if the credentials are invalid.
|
||||
// e.g. return { id: 1, name: 'J Smith', email: 'jsmith@example.com' }
|
||||
// You can also use the request object to obtain additional parameters
|
||||
// (i.e., the request IP address)
|
||||
return null
|
||||
}
|
||||
if (user) {
|
||||
@@ -282,10 +284,10 @@ The Credentials provider can only be used if JSON Web Tokens are enabled for ses
|
||||
|
||||
### Options
|
||||
|
||||
| Name | Description | Type | Required |
|
||||
| :---------: | :-----------------------------------------------: | :------------------------------: | :------: |
|
||||
| id | Unique ID for the provider | `string` | Yes |
|
||||
| name | Descriptive name for the provider | `string` | Yes |
|
||||
| type | Type of provider, in this case `credentials` | `"credentials"` | Yes |
|
||||
| credentials | The credentials to sign-in with | `Object` | Yes |
|
||||
| authorize | Callback to execute once user is to be authorized | `(credentials) => Promise<User>` | Yes |
|
||||
| Name | Description | Type | Required |
|
||||
| :---------: | :-----------------------------------------------: | :-----------------------------------: | :------: |
|
||||
| id | Unique ID for the provider | `string` | Yes |
|
||||
| name | Descriptive name for the provider | `string` | Yes |
|
||||
| type | Type of provider, in this case `credentials` | `"credentials"` | Yes |
|
||||
| credentials | The credentials to sign-in with | `Object` | Yes |
|
||||
| authorize | Callback to execute once user is to be authorized | `(credentials, req) => Promise<User>` | Yes |
|
||||
|
||||
@@ -39,6 +39,8 @@ The Credentials provider is specified like other providers, except that you need
|
||||
|
||||
If you throw an Error, the user will be sent to the error page with the error message as a query parameter. If throw a URL (a string), the user will be redirected to the URL.
|
||||
|
||||
The Credentials provider's `authorize()` method also provides the request object as the second parameter (see example below).
|
||||
|
||||
```js title="pages/api/auth/[...nextauth].js"
|
||||
import Providers from `next-auth/providers`
|
||||
...
|
||||
@@ -53,7 +55,7 @@ providers: [
|
||||
username: { label: "Username", type: "text", placeholder: "jsmith" },
|
||||
password: { label: "Password", type: "password" }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
async authorize(credentials, req) {
|
||||
// Add logic here to look up the user from the credentials supplied
|
||||
const user = { id: 1, name: 'J Smith', email: 'jsmith@example.com' }
|
||||
|
||||
@@ -90,7 +92,7 @@ As with all providers, the order you specify them is the order they are displaye
|
||||
Providers.Credentials({
|
||||
id: 'domain-login',
|
||||
name: "Domain Account",
|
||||
async authorize(credentials) {
|
||||
async authorize(credentials, req) {
|
||||
const user = { /* add function to get user */ }
|
||||
return user
|
||||
},
|
||||
@@ -103,7 +105,7 @@ As with all providers, the order you specify them is the order they are displaye
|
||||
Providers.Credentials({
|
||||
id: 'intranet-credentials',
|
||||
name: "Two Factor Auth",
|
||||
async authorize(credentials) {
|
||||
async authorize(credentials, req) {
|
||||
const user = { /* add function to get user */ }
|
||||
return user
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ export default NextAuth({
|
||||
username: { label: "DN", type: "text", placeholder: "" },
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
async authorize(credentials, req) {
|
||||
// You might want to pull this call out so we're not making a new LDAP client on every login attemp
|
||||
const client = ldap.createClient({
|
||||
url: process.env.LDAP_URI,
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
module.exports = {
|
||||
title: 'NextAuth.js',
|
||||
tagline: 'Authentication for Next.js',
|
||||
url: 'https://next-auth.js.org',
|
||||
baseUrl: '/',
|
||||
favicon: 'img/favicon.ico',
|
||||
organizationName: 'nextauthjs',
|
||||
projectName: 'next-auth',
|
||||
title: "NextAuth.js",
|
||||
tagline: "Authentication for Next.js",
|
||||
url: "https://next-auth.js.org",
|
||||
baseUrl: "/",
|
||||
favicon: "img/favicon.ico",
|
||||
organizationName: "nextauthjs",
|
||||
projectName: "next-auth",
|
||||
themeConfig: {
|
||||
sidebarCollapsible: true,
|
||||
prism: {
|
||||
theme: require('prism-react-renderer/themes/vsDark')
|
||||
theme: require("prism-react-renderer/themes/vsDark"),
|
||||
},
|
||||
navbar: {
|
||||
title: 'NextAuth.js',
|
||||
title: "NextAuth.js",
|
||||
logo: {
|
||||
alt: 'NextAuth Logo',
|
||||
src: 'img/logo/logo-xs.png'
|
||||
alt: "NextAuth Logo",
|
||||
src: "img/logo/logo-xs.png",
|
||||
},
|
||||
items: [
|
||||
{
|
||||
to: '/getting-started/introduction',
|
||||
activeBasePath: 'docs',
|
||||
label: 'Documentation',
|
||||
position: 'left'
|
||||
to: "/getting-started/introduction",
|
||||
activeBasePath: "docs",
|
||||
label: "Documentation",
|
||||
position: "left",
|
||||
},
|
||||
{
|
||||
to: '/tutorials',
|
||||
activeBasePath: 'docs',
|
||||
label: 'Tutorials',
|
||||
position: 'left'
|
||||
to: "/tutorials",
|
||||
activeBasePath: "docs",
|
||||
label: "Tutorials",
|
||||
position: "left",
|
||||
},
|
||||
{
|
||||
to: '/faq',
|
||||
activeBasePath: 'docs',
|
||||
label: 'FAQ',
|
||||
position: 'left'
|
||||
to: "/faq",
|
||||
activeBasePath: "docs",
|
||||
label: "FAQ",
|
||||
position: "left",
|
||||
},
|
||||
{
|
||||
href: 'https://www.npmjs.com/package/next-auth',
|
||||
label: 'npm',
|
||||
position: 'right'
|
||||
href: "https://www.npmjs.com/package/next-auth",
|
||||
label: "npm",
|
||||
position: "right",
|
||||
},
|
||||
{
|
||||
href: 'https://github.com/nextauthjs/next-auth',
|
||||
label: 'GitHub',
|
||||
position: 'right'
|
||||
}
|
||||
]
|
||||
href: "https://github.com/nextauthjs/next-auth",
|
||||
label: "GitHub",
|
||||
position: "right",
|
||||
},
|
||||
],
|
||||
},
|
||||
// announcementBar: {
|
||||
// id: 'release-candiate-announcement',
|
||||
@@ -57,45 +57,45 @@ module.exports = {
|
||||
footer: {
|
||||
links: [
|
||||
{
|
||||
title: 'About NextAuth.js',
|
||||
title: "About NextAuth.js",
|
||||
items: [
|
||||
{
|
||||
label: 'Introduction',
|
||||
to: '/getting-started/introduction'
|
||||
label: "Introduction",
|
||||
to: "/getting-started/introduction",
|
||||
},
|
||||
{
|
||||
label: 'Contributors',
|
||||
to: '/contributors'
|
||||
label: "Contributors",
|
||||
to: "/contributors",
|
||||
},
|
||||
{
|
||||
label: 'Canary documentation',
|
||||
to: 'https://next-auth-git-canary.nextauthjs.vercel.app/'
|
||||
}
|
||||
]
|
||||
label: "Canary documentation",
|
||||
to: "https://next-auth-git-canary.nextauthjs.vercel.app/",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Download',
|
||||
title: "Download",
|
||||
items: [
|
||||
{
|
||||
label: 'GitHub',
|
||||
to: 'https://github.com/nextauthjs/next-auth'
|
||||
label: "GitHub",
|
||||
to: "https://github.com/nextauthjs/next-auth",
|
||||
},
|
||||
{
|
||||
label: 'NPM',
|
||||
to: 'https://www.npmjs.com/package/next-auth'
|
||||
}
|
||||
]
|
||||
label: "NPM",
|
||||
to: "https://www.npmjs.com/package/next-auth",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Acknowledgements',
|
||||
title: "Acknowledgements",
|
||||
items: [
|
||||
{
|
||||
label: 'Docusaurus',
|
||||
to: 'https://v2.docusaurus.io/'
|
||||
label: "Docusaurus",
|
||||
to: "https://v2.docusaurus.io/",
|
||||
},
|
||||
{
|
||||
label: 'Images by unDraw',
|
||||
to: 'https://undraw.co/'
|
||||
label: "Images by unDraw",
|
||||
to: "https://undraw.co/",
|
||||
},
|
||||
{
|
||||
html: `
|
||||
@@ -106,28 +106,28 @@ module.exports = {
|
||||
height="32"
|
||||
src="https://raw.githubusercontent.com/nextauthjs/next-auth/canary/www/static/img/powered-by-vercel.svg"
|
||||
/>
|
||||
</a>`
|
||||
}
|
||||
]
|
||||
}
|
||||
</a>`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
copyright: 'NextAuth.js © Iain Collins 2021'
|
||||
}
|
||||
copyright: "NextAuth.js © Iain Collins 2021",
|
||||
},
|
||||
},
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
"@docusaurus/preset-classic",
|
||||
{
|
||||
docs: {
|
||||
routeBasePath: '/',
|
||||
sidebarPath: require.resolve('./sidebars.js'),
|
||||
editUrl: 'https://github.com/nextauthjs/next-auth/edit/main/www'
|
||||
routeBasePath: "/",
|
||||
sidebarPath: require.resolve("./sidebars.js"),
|
||||
editUrl: "https://github.com/nextauthjs/next-auth/edit/main/www",
|
||||
},
|
||||
theme: {
|
||||
customCss: require.resolve('./src/css/index.css')
|
||||
}
|
||||
}
|
||||
]
|
||||
customCss: require.resolve("./src/css/index.css"),
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
plugins: ['docusaurus-lunr-search']
|
||||
plugins: ["docusaurus-lunr-search"],
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ html[data-theme="dark"] hr {
|
||||
|
||||
.navbar__item.navbar__link[href*="github"],
|
||||
.navbar__item.navbar__link[href*="npmjs"] {
|
||||
padding: 0 1rem 0 0;
|
||||
padding: 0 1.5rem 0 0;
|
||||
display: flex;
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ import { useHistory } from "@docusaurus/router"
|
||||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"
|
||||
import "./styles.css"
|
||||
|
||||
const kFormatter = (num) => {
|
||||
return Math.sign(num) * (Math.abs(num) / 1000).toFixed(1) + "k"
|
||||
}
|
||||
|
||||
let loaded = false
|
||||
const Search = (props) => {
|
||||
const initialized = useRef(false)
|
||||
@@ -84,6 +88,17 @@ const Search = (props) => {
|
||||
searchBarRef.current.focus()
|
||||
}
|
||||
})
|
||||
fetch("https://api.github.com/repos/nextauthjs/next-auth")
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
const navLinks = document.getElementsByClassName(
|
||||
"navbar__item navbar__link"
|
||||
)
|
||||
const githubStat = document.createElement("span")
|
||||
githubStat.innerHTML = kFormatter(data.stargazers_count)
|
||||
githubStat.className = "github-counter"
|
||||
navLinks[4].appendChild(githubStat)
|
||||
})
|
||||
return () => document.removeEventListener("keypress")
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -33,6 +33,22 @@
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.github-counter {
|
||||
position: absolute;
|
||||
color: #000;
|
||||
top: -10px;
|
||||
right: 5px;
|
||||
font-size: 9px;
|
||||
background-color: #ccc;
|
||||
padding: 2px 5px;
|
||||
border-radius: 10px;
|
||||
z-index: -1;
|
||||
}
|
||||
html[data-theme="dark"] .github-counter {
|
||||
background-color: #222;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
@media (max-width: 360px) {
|
||||
.search-bar {
|
||||
width: 0 !important;
|
||||
|
||||
Reference in New Issue
Block a user