Compare commits

...

11 Commits

Author SHA1 Message Date
Ashutosh Kumar
fb04ab4e76 fix(ts): make GetSessionOptions optional (#1851) 2021-04-25 15:39:19 +02:00
Ashutosh Kumar
07e2a83ccb fix(ts): make ctxOrReq optional in getCsrfToken() (#1850) 2021-04-25 14:10:21 +02:00
Balázs Orbán
065d9eb310 chore(release): do not mark released PRs/issues (#1845) 2021-04-24 23:17:24 +02:00
Thanayut T
5da19f3c9a feat(provider): add WordPress.com provider (#1837) 2021-04-24 10:48:44 +02:00
Balázs Orbán
88ec3bad71 chore: move files from root 2021-04-24 00:44:08 +02:00
Lluis Agusti
5ab7868533 chore(ci): remove Node 10 and add Node 16 (#1830)
* chore(github): add CODEOWNERS

* chore(ci): remove Node 10 and add Node 16
2021-04-24 00:20:50 +02:00
Lluis Agusti
835dda0899 chore(github): add CODEOWNERS (#1827) 2021-04-24 00:17:19 +02:00
Wilkins Fernandez
ad4709764a docs: update import for providers (#1823)
Updates the names export from `providers` to `getProviders`.
2021-04-23 14:58:53 +02:00
Michał Bundyra
55a2932973 fix(ts): add Mailchimp provider (#1821) 2021-04-23 13:11:13 +02:00
Michał Bundyra
49cb7e5bd7 feat(provider): add Mailchimp provider (#1781) 2021-04-23 12:15:25 +02:00
Balázs Orbán
b95182ded7 fix(ts): expose errors type delcarations (#1817) 2021-04-22 23:45:23 +02:00
19 changed files with 178 additions and 34 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1 @@
/types/ @balazsorban44 @lluia

View File

View File

@@ -4,22 +4,22 @@ name: Lint/Build
on:
push:
branches:
- main
- beta
- next
branches:
- main
- beta
- next
pull_request:
branches:
- main
- beta
- next
- main
- beta
- next
jobs:
lint-and-build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10, 12, 14]
node-version: [12, 14, 16]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
@@ -29,4 +29,4 @@ jobs:
- name: Install dependencies
uses: bahmutov/npm-install@v1
- run: npm run lint
- run: npm run build
- run: npm run build

View File

@@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
node-version: [10, 12, 14]
node-version: [12, 14, 16]
steps:
- uses: actions/checkout@v2

View File

@@ -19,6 +19,8 @@ jobs:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Check types

25
.gitignore vendored
View File

@@ -27,18 +27,19 @@ node_modules
.cache-loader
www/providers.json
src/providers/index.js
internals
adapters.d.ts
adapters.js
client.d.ts
client.js
index.d.ts
index.js
jwt.d.ts
jwt.js
providers.d.ts
providers.js
errors.js
/internals
/adapters.d.ts
/adapters.js
/client.d.ts
/client.js
/index.d.ts
/index.js
/jwt.d.ts
/jwt.js
/providers.d.ts
/providers.js
/errors.js
/errors.d.ts
# Development app
app/next-auth

View File

@@ -36,6 +36,7 @@ const TYPES_TARGETS = [
`${MODULE_ENTRIES.ADAPTERS}.d.ts`,
`${MODULE_ENTRIES.PROVIDERS}.d.ts`,
`${MODULE_ENTRIES.JWT}.d.ts`,
`${MODULE_ENTRIES.ERRORS}.d.ts`,
"internals",
]

View File

@@ -66,10 +66,11 @@
"adapters.d.ts",
"client.js",
"client.d.ts",
"errors.js",
"errors.d.ts",
"jwt.js",
"jwt.d.ts",
"internals",
"errors.js"
"internals"
],
"license": "ISC",
"dependencies": {
@@ -179,6 +180,18 @@
"name": "next",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"releasedLabels": false,
"successComment": false
}
]
]
},
"funding": [

View File

@@ -0,0 +1,22 @@
export default function Mailchimp(options) {
return {
id: 'mailchimp',
name: 'Mailchimp',
type: 'oauth',
version: '2.0',
scope: '',
params: { grant_type: 'authorization_code' },
accessTokenUrl: 'https://login.mailchimp.com/oauth2/token',
authorizationUrl: 'https://login.mailchimp.com/oauth2/authorize?response_type=code',
profileUrl: 'https://login.mailchimp.com/oauth2/metadata',
profile: (profile) => {
return {
id: profile.login.login_id,
name: profile.accountname,
email: profile.login.email,
image: null
}
},
...options
}
}

View File

@@ -0,0 +1,23 @@
export default function WordPress(options) {
return {
id: "wordpress",
name: "WordPress.com",
type: "oauth",
version: "2.0",
scope: "auth",
params: { grant_type: "authorization_code" },
accessTokenUrl: "https://public-api.wordpress.com/oauth2/token",
authorizationUrl:
"https://public-api.wordpress.com/oauth2/authorize?response_type=code",
profileUrl: "https://public-api.wordpress.com/rest/v1/me",
profile(profile) {
return {
id: profile.ID,
name: profile.display_name,
email: profile.email,
image: profile.avatar_URL,
}
},
...options,
}
}

View File

@@ -1,5 +1,6 @@
# Rename file to .env and populate values
# to be able to run tests
# To be able to run tests:
# 1. copy to the root folder and rename to .env
# 2. Populate with values
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_TWITTER_ID=
NEXTAUTH_TWITTER_SECRET=

View File

@@ -2,14 +2,13 @@
#
# Note: Uses Docker Compose v2 as v3 doesn't currently support extends.
# https://docs.docker.com/compose/compose-file/compose-file-v2/
version: '2.3'
version: "2.3"
services:
app:
build:
context: ../../
dockerfile: Dockerfile
dockerfile: ./test/Dockerfile
environment:
# Set env vars in your current terminal or in .env in the root directory
- NEXTAUTH_URL=${NEXTAUTH_URL}

4
types/client.d.ts vendored
View File

@@ -32,7 +32,7 @@ export function useSession(): [Session | null, boolean]
*
* [Documentation](https://next-auth.js.org/getting-started/client#getsession)
*/
export function getSession(options: GetSessionOptions): Promise<Session | null>
export function getSession(options?: GetSessionOptions): Promise<Session | null>
/**
* Alias for `getSession`
@@ -52,7 +52,7 @@ export const session: typeof getSession
*
* [Documentation](https://next-auth.js.org/getting-started/client#getcsrftoken)
*/
export function getCsrfToken(ctxOrReq: CtxOrReq): Promise<string | null>
export function getCsrfToken(ctxOrReq?: CtxOrReq): Promise<string | null>
/**
* Alias for `getCsrfToken`

23
types/errors.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
/**
* Same as the default `Error`, but it is JSON serializable.
* @source https://iaincollins.medium.com/error-handling-in-javascript-a6172ccdf9af
*/
export class UnknownError extends Error {}
export class OAuthCallbackError extends UnknownError {}
export class AccountNotLinkedError extends UnknownError {}
export class CreateUserError extends UnknownError {}
export class GetUserError extends UnknownError {}
export class GetUserByEmailError extends UnknownError {}
export class GetUserByIdError extends UnknownError {}
export class GetUserByProviderAccountIdError extends UnknownError {}
export class UpdateUserError extends UnknownError {}
export class DeleteUserError extends UnknownError {}
export class LinkAccountError extends UnknownError {}
export class UnlinkAccountError extends UnknownError {}
export class CreateSessionError extends UnknownError {}
export class GetSessionError extends UnknownError {}
export class UpdateSessionError extends UnknownError {}
export class DeleteSessionError extends UnknownError {}
export class CreateVerificationRequestError extends UnknownError {}
export class GetVerificationRequestError extends UnknownError {}
export class DeleteVerificationRequestError extends UnknownError {}

View File

@@ -77,6 +77,7 @@ export type OAuthProviderType =
| "Kakao"
| "LINE"
| "LinkedIn"
| "Mailchimp"
| "MailRu"
| "Medium"
| "Netlify"
@@ -90,6 +91,7 @@ export type OAuthProviderType =
| "Twitch"
| "Twitter"
| "VK"
| "WordPress"
| "Yandex"
| "Zoho"

View File

@@ -60,7 +60,7 @@ By default, the built-in pages will follow the system theme, utilizing the [`pre
In order to get the available authentication providers and the URLs to use for them, you can make a request to the API endpoint `/api/auth/providers`:
```jsx title="pages/auth/signin.js"
import { providers, signIn } from 'next-auth/client'
import { getProviders, signIn } from 'next-auth/client'
export default function SignIn({ providers }) {
return (
@@ -76,7 +76,7 @@ export default function SignIn({ providers }) {
// This is the recommended way for Next.js 9.3 or newer
export async function getServerSideProps(context){
const providers = await providers()
const providers = await getProviders()
return {
props: { providers }
}
@@ -86,7 +86,7 @@ export async function getServerSideProps(context){
// If older than Next.js 9.3
SignIn.getInitialProps = async () => {
return {
providers: await providers()
providers: await getProviders()
}
}
*/

View File

@@ -0,0 +1,26 @@
---
id: mailchimp
title: Mailchimp
---
## Documentation
https://mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/
## Configuration
https://admin.mailchimp.com/account/oauth2/client/
## Example
```js
import Providers from `next-auth/providers`
...
providers: [
Providers.Mailchimp({
clientId: process.env.MAILCHIMP_CLIENT_ID,
clientSecret: process.env.MAILCHIMP_CLIENT_SECRET
})
]
...
```

View File

@@ -0,0 +1,30 @@
---
id: wordpress
title: WordPress.com
---
## Documentation
https://developer.wordpress.com/docs/oauth2/
## Configuration
https://developer.wordpress.com/apps/
## Example
```js
import Providers from `next-auth/providers`
...
providers: [
Providers.WordPress({
clientId: process.env.WORDPRESS_CLIENT_ID,
clientSecret: process.env.WORDPRESS_CLIENT_SECRET
})
}
...
```
:::tip
Register your application to obtain Client ID and Client Secret at https://developer.wordpress.com/apps/ Select Type as Web and set Redirect URL to `http://example.com/api/auth/callback/wordpress` where example.com is your site domain.
:::