Skip to content

Commit

Permalink
Merge branch 'main' into remix-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyEntropy committed Feb 20, 2023
2 parents 23d9dbe + 3d7985f commit 53ae974
Show file tree
Hide file tree
Showing 97 changed files with 3,212 additions and 3,366 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pnpm-lock.yaml

.docusaurus
build
docs/docs/reference/03-core
docs/docs/reference/04-sveltekit
docs/docs/reference/core
docs/docs/reference/sveltekit
static

# --------------- Packages ---------------
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1_bug_framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ body:
Run this command in your project's root folder and paste the result:
```sh
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth"
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth,@auth/*"
```
Alternatively, you can manually gather the version information from your package.json for these packages: "next", "react" and "next-auth". Please also mention your OS and Node.js version, as well as the browser you are using.
validations:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/2_bug_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ body:
- "Medium"
- "Naver"
- "Netlify"
- "Notion"
- "Okta"
- "OneLogin"
- "Osso"
Expand Down Expand Up @@ -88,7 +89,7 @@ body:
Run this command in your project's root folder and paste the result:
```sh
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth"
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth,@auth/*"
```
Alternatively, you can manually gather the version information from your package.json for these packages: "next", "react" and "next-auth". Please also mention your OS and Node.js version, as well as the browser you are using.
validations:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/3_bug_adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ body:
Run this command in your project's root folder and paste the result:
```sh
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth" && npx envinfo --npmPackages "@next-auth/*"
npx envinfo --system --binaries --browsers --npmPackages "next,react,next-auth,@auth/*" && npx envinfo --npmPackages "@next-auth/*"
```
Alternatively, if the above command did not work, we need the version of the following packages from your package.json: "next", "react", "next-auth" and your adapter. Please also mention your OS and Node.js version, as well as the browser you are using.
validations:
Expand Down
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log
ui-debug.log
.pnpm-debug.log


Expand All @@ -34,13 +35,10 @@ packages/next-auth/utils
packages/next-auth/core
packages/next-auth/jwt
packages/next-auth/react
packages/next-auth/adapters.d.ts
packages/next-auth/adapters.js
packages/next-auth/index.d.ts
packages/next-auth/index.js
packages/next-auth/next
packages/next-auth/middleware.d.ts
packages/next-auth/middleware.js
packages/*/*.js
packages/*/*.d.ts
packages/*/*.d.ts.map

# Development app
apps/dev/src/css
Expand Down Expand Up @@ -81,14 +79,12 @@ docs/.docusaurus
docs/providers.json

# Core
packages/core/*.js
packages/core/*.d.ts
packages/core/*.d.ts.map
packages/core/src/providers/oauth-types.ts
packages/core/lib
packages/core/providers
packages/core/src/lib/pages/styles.ts
docs/docs/reference/03-core
docs/docs/reference/04-sveltekit
docs/docs/reference/core
docs/docs/reference/sveltekit


# SvelteKit
Expand All @@ -98,3 +94,7 @@ packages/frameworks-sveltekit/.svelte-kit
packages/frameworks-sveltekit/package
packages/frameworks-sveltekit/vite.config.js.timestamp-*
packages/frameworks-sveltekit/vite.config.ts.timestamp-*

# Adapters

docs/docs/reference/adapter
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pnpm-lock.yaml

.docusaurus
build
docs/docs/reference/03-core
docs/docs/reference/04-sveltekit
docs/docs/reference/core
docs/docs/reference/sveltekit
static
docs/providers.json

Expand Down
4 changes: 4 additions & 0 deletions apps/dev/nextjs/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ KEYCLOAK_ID=
KEYCLOAK_SECRET=
KEYCLOAK_ISSUER=

NOTION_ID=
NOTION_SECRET=
NOTION_REDIRECT_URI=

IDS4_ID=
IDS4_SECRET=
IDS4_ISSUER=
Expand Down
4 changes: 3 additions & 1 deletion apps/dev/nextjs/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Instagram from "@auth/core/providers/instagram"
import Line from "@auth/core/providers/line"
import LinkedIn from "@auth/core/providers/linkedin"
import Mailchimp from "@auth/core/providers/mailchimp"
import Notion from "@auth/core/providers/notion"
// import Okta from "@auth/core/providers/okta"
import Osu from "@auth/core/providers/osu"
import Patreon from "@auth/core/providers/patreon"
Expand Down Expand Up @@ -69,7 +70,7 @@ import WorkOS from "@auth/core/providers/workos"

export const authConfig: AuthConfig = {
// adapter,
// debug: process.env.NODE_ENV !== "production",
debug: process.env.NODE_ENV !== "production",
theme: {
logo: "https://next-auth.js.org/img/logo/logo-sm.png",
brandColor: "#1786fb",
Expand Down Expand Up @@ -107,6 +108,7 @@ export const authConfig: AuthConfig = {
Line({ clientId: process.env.LINE_ID, clientSecret: process.env.LINE_SECRET }),
LinkedIn({ clientId: process.env.LINKEDIN_ID, clientSecret: process.env.LINKEDIN_SECRET }),
Mailchimp({ clientId: process.env.MAILCHIMP_ID, clientSecret: process.env.MAILCHIMP_SECRET }),
Notion({ clientId: process.env.NOTION_ID, clientSecret: process.env.NOTION_SECRET, redirectUri: process.env.NOTION_REDIRECT_URI }),
// Okta({ clientId: process.env.OKTA_ID, clientSecret: process.env.OKTA_SECRET, issuer: process.env.OKTA_ISSUER }),
Osu({ clientId: process.env.OSU_CLIENT_ID, clientSecret: process.env.OSU_CLIENT_SECRET }),
Patreon({ clientId: process.env.PATREON_ID, clientSecret: process.env.PATREON_SECRET }),
Expand Down
4 changes: 2 additions & 2 deletions apps/dev/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"vite": "4.0.1"
},
"dependencies": {
"@auth/core": "0.2.5",
"@auth/sveltekit": "0.1.12"
"@auth/core": "workspace:*",
"@auth/sveltekit": "workspace:*"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion apps/examples/solid-start/src/routes/protected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Protected } from "~/components";
export const { routeData, Page } = Protected((session) => {
return (
<main class="flex flex-col gap-2 items-center">
<h1>This is a proteced route</h1>
<h1>This is a protected route</h1>
</main>
);
});
Expand Down
7 changes: 3 additions & 4 deletions apps/playgrounds/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "playground-nuxt",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "export NODE_OPTIONS='--no-experimental-fetch' && nuxt dev",
"build": "nuxt prepare && nuxt build",
"dev": "nuxt prepare && export NODE_OPTIONS='--no-experimental-fetch' && nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.1.1",
Expand Down
8 changes: 5 additions & 3 deletions docs/docs/getting-started/02-oauth-tutorial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import startAppAndSignInImg from "./img/getting-started-app-start.png"
import githubAuthCredentials from "./img/getting-started-github-auth.png"
import nextAuthUserLoggedIn from "./img/getting-started-nextauth-success.png"

We know, authentication is hard. Is a rabbit hole and it's easy to get lost on it. The goal of making Auth.js is that you can add authentication easily to your project with just a few lines of code.
We know, authentication is hard. It's a rabbit hole and it's easy to get lost on it. The goal of making Auth.js is that you can add authentication easily to your project with just a few lines of code.

The easiest way is to setup Auth.js with an [OAuth](https://en.wikipedia.org/wiki/OAuth) provider. In this tutorial we'll be setting Auth.js in a **Next.js app** to be able to login with **Github**.

Expand Down Expand Up @@ -214,7 +214,7 @@ Note that, for each provider, the configuration process will be similar to what
2. Create create your OAuth application within it
3. Set the callback URL
4. Get the Client ID and Generate a Client Secret
:::
:::

## 3. Wiring all together

Expand Down Expand Up @@ -253,11 +253,13 @@ Once inserted and correct, Github will redirect the user to our app and Auth.js
<img src={nextAuthUserLoggedIn} />

Great! We have completed the whole E2E authentication flow setup so that users can login in our application through Github!
:::

:::info
You can create your own Sign In page instead of using the default one from Auth.js. You can learn how to do so in our dedicated guide for it.
You can create your own Sign In page instead of using the default one from Auth.js. You can learn how to do so in our [dedicated guide for it](/guides/basics/pages).
:::


## 4. Deploying to production

### Configuring different environments
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/getting-started/03-email-tutorial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export default NextAuth({
providers: [
Email({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: Number(process.env.EMAIL_SERVER_PORT),
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
Expand Down Expand Up @@ -147,8 +147,8 @@ import EmailProvider from "next-auth/providers/email"

export default NextAuth({
secret: process.env.NEXTAUTH_SECRET,
+ adapter: MongoDBAdapter(clientPromise),
providers: [
+ adapter: MongoDBAdapter(clientPromise),
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
Expand Down Expand Up @@ -188,7 +188,7 @@ Let's now check our email, and look for one sent from NextAuth (check your spam

<img src={mailboxImg} alt="Screenshot of mailbox" />

Nice! We got one, coming from the sender specified in the `EMAIL_FROM` environment variable from our configuration above and that's is the sender we verified in Sengrid.
Nice! We got one, coming from the sender specified in the `EMAIL_FROM` environment variable from our configuration above and that's is the sender we verified in Sendgrid.

Click on "Sign in" and a new browser tab will open, you should then land on your application as authenticated!

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/guides/03-basics/refresh-token-rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Using a JWT to store the `refresh_token` is less secure than saving it in a data

#### JWT strategy

Using the [jwt](../../reference/03-core/interfaces/types.CallbacksOptions.md#jwt) and [session](../../reference/03-core/interfaces/types.CallbacksOptions.md#session) callbacks, we can persist OAuth tokens and refresh them when they expire.
Using the [jwt](../../reference/core/types#jwt) and [session](../../reference/core/types#session) callbacks, we can persist OAuth tokens and refresh them when they expire.

Below is a sample implementation using Google's Identity Provider. Please note that the OAuth 2.0 request in the `refreshAccessToken()` function will vary between different providers, but the core logic should remain similar.

Expand All @@ -45,10 +45,10 @@ export default Auth(new Request("https://example.com"), {
// Save the access token and refresh token in the JWT on the initial login
return {
access_token: account.access_token,
expires_at: Date.now() + account.expires_in * 1000,
expires_at: Math.floor(Date.now() / 1000 + account.expires_in),
refresh_token: account.refresh_token,
}
} else if (Date.now() < token.expires_at) {
} else if (Date.now() < token.expires_at * 1000) {
// If the access token has not expired yet, return it
return token
} else {
Expand All @@ -74,7 +74,7 @@ export default Auth(new Request("https://example.com"), {
return {
...token, // Keep the previous token properties
access_token: tokens.access_token,
expires_at: Date.now() + tokens.expires_in * 1000,
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
// Fall back to old refresh token, but note that
// many providers may only allow using a refresh token once.
refresh_token: tokens.refresh_token ?? token.refresh_token,
Expand Down Expand Up @@ -136,7 +136,7 @@ export default Auth(new Request("https://example.com"), {
const [google] = await prisma.account.findMany({
where: { userId: user.id, provider: "google" },
})
if (google.expires_at < Date.now()) {
if (google.expires_at * 1000 < Date.now()) {
// If the access token has expired, try to refresh it
try {
// https://accounts.google.com/.well-known/openid-configuration
Expand All @@ -159,7 +159,7 @@ export default Auth(new Request("https://example.com"), {
await prisma.account.update({
data: {
access_token: tokens.access_token,
expires_at: Date.now() + tokens.expires_in * 1000,
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
refresh_token: tokens.refresh_token ?? google.refresh_token,
},
where: {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/07-corporate-proxies/corporate-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Corporate proxy
---

Using Auth.js behind a corporate proxy is not supported out of the box. This is due to the fact that the underlying library we use, [`openid-client`](https://npm.im/openid-client) which uses the built-in Node.js `http` / `https` libraries, and those do not support proxys by default:
Using Auth.js behind a corporate proxy is not supported out of the box. This is due to the fact that the underlying library we use, [`openid-client`](https://npm.im/openid-client) which uses the built-in Node.js `http` / `https` libraries, and those do not support proxies by default:

- [`http` docs](https://nodejs.org/dist/latest-v18.x/docs/api/http.html)
- [`https` docs](https://nodejs.org/dist/latest-v18.x/docs/api/https.html)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/08-other/ldap-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default NextAuth({
password: { label: "Password", type: "password" },
},
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
// You might want to pull this call out so we're not making a new LDAP client on every login attempt
const client = ldap.createClient({
url: process.env.LDAP_URI,
})
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/reference/04-solidstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ AUTH_SECRET=your_auth_secret
in this example we are using github so make sure to set the following environment variables:

```
GITHUB_ID=your_github_oatuh_id
GITHUB_SECRET=your_github_oatuh_secret
GITHUB_ID=your_github_oauth_id
GITHUB_SECRET=your_github_oauth_secret
```

```ts
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/reference/04-solidstart/protected.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ When using SSR, I recommend creating a `Protected` component that will trigger s

```tsx
// components/Protected.tsx
import { type Session } from "@auth/core";
import { type Session } from "@auth/core/types";
import { getSession } from "@auth/solid-start";
import { Component, Show } from "solid-js";
import { useRouteData } from "solid-start";
Expand Down Expand Up @@ -60,7 +60,7 @@ import Protected from "~/components/Protected";
export const { routeData, Page } = Protected((session) => {
return (
<main class="flex flex-col gap-2 items-center">
<h1>This is a proteced route</h1>
<h1>This is a protected route</h1>
</main>
);
});
Expand Down Expand Up @@ -110,7 +110,7 @@ And now you can easily create a protected route:
export default () => {
return (
<main class="flex flex-col gap-2 items-center">
<h1>This is a proteced route</h1>
<h1>This is a protected route</h1>
</main>
);
};
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/05-oauth-providers/trakt.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ providers: [
```

:::warning
Trakt does not allow hotlinking images. Even the authenticated user's profie picture.
Trakt does not allow hotlinking images. Even the authenticated user's profile picture.
:::

:::warning
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/06-adapters/dgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type VerificationToken {
## Securing your database

For production deployments you will want to restrict the access to the types used
by next-auth. The main form of access control used in Dgraph is via `@auth` directive alongide types in the schema.
by next-auth. The main form of access control used in Dgraph is via `@auth` directive alongside types in the schema.

#### Secure schema

Expand Down
Loading

0 comments on commit 53ae974

Please sign in to comment.