Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 5, 2020
2 parents 3979591 + f9cb5ac commit c8b8308
Show file tree
Hide file tree
Showing 143 changed files with 2,221 additions and 2,246 deletions.
7 changes: 7 additions & 0 deletions docs/basic-features/built-in-css-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ npm install sass

Sass support has the same benefits and restrictions as the built-in CSS support detailed above.

> **Note**: Sass supports [two different syntaxes](https://sass-lang.com/documentation/syntax), each with their own extension.
> The `.scss` extension requires you use the [SCSS syntax](https://sass-lang.com/documentation/syntax#scss),
> while the `.sass` extension requires you use the [Indented Syntax ("Sass")](https://sass-lang.com/documentation/syntax#the-indented-syntax).
>
> If you're not sure which to choose, start with the `.scss` extension which is a superset of CSS, and doesn't require you learn the
> Indented Syntax ("Sass").
### Customizing Sass Options

If you want to configure the Sass compiler you can do so by using `sassOptions` in `next.config.js`.
Expand Down
55 changes: 55 additions & 0 deletions docs/create-next-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
description: Create Next.js apps in one command with create-next-app.
---

# Create Next App

The easiest way to get started with Next.js is by using `create-next-app`. This simple CLI tool enables you to quickly start building a new Next.js application, with everything set up for you. You can create a new app using the default Next.js template, or by using one of the [official Next.js examples](https://github.com/vercel/next.js/tree/canary/examples). To get started, use the following command:

```bash
npx create-next-app
# or
yarn create next-app
```

### Options

`create-next-app` comes with the following options:

- **-e, --example [name]|[github-url]** - An example to bootstrap the app with. You can use an example name from the [Next.js repo](https://github.com/vercel/next.js/tree/master/examples) or a GitHub URL. The URL can use any branch and/or subdirectory.
- **--example-path [path-to-example]** - In a rare case, your GitHub URL might contain a branch name with a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar). In this case, you must specify the path to the example separately: `--example-path foo/bar`

### Why use Create Next App?

`create-next-app` allows you to create a new Next.js app within seconds. It is officially maintained by the creators of Next.js, and includes a number of benefits:

- **Interactive Experience**: Running `npx create-next-app` (with no arguments) launches an interactive experience that guides you through setting up a project.
- **Zero Dependencies**: Initializing a project is as quick as one second. Create Next App has zero dependencies.
- **Offline Support**: Create Next App will automatically detect if you're offline and bootstrap your project using your local package cache.
- **Support for Examples**: Create Next App can bootstrap your application using an example from the Next.js examples collection (e.g. `npx create-next-app --example api-routes`).
- **Tested**: The package is part of the Next.js monorepo and tested using the same integration test suite as Next.js itself, ensuring it works as expected with every release.

## Related

For more information on what to do next, we recommend the following sections:

<div class="card">
<a href="/docs/basic-features/pages.md">
<b>Pages:</b>
<small>Learn more about what pages are in Next.js.</small>
</a>
</div>

<div class="card">
<a href="/docs/basic-features/built-in-css-support.md">
<b>CSS Support:</b>
<small>Use the built-in CSS support to add custom styles to your app.</small>
</a>
</div>

<div class="card">
<a href="/docs/api-reference/cli.md">
<b>CLI:</b>
<small>Learn more about the Next.js CLI.</small>
</a>
</div>
2 changes: 2 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ yarn create next-app

After the installation is complete, follow the instructions to start the development server. Try editing `pages/index.js` and see the result on your browser.

For more information on how to use `create-next-app`, you can review the [`create-next-app` documentation](/docs/create-next-app.md)

## Manual Setup

Install `next`, `react` and `react-dom` in your project:
Expand Down
13 changes: 13 additions & 0 deletions errors/invalid-external-rewrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Invalid External Rewrite

#### Why This Error Occurred

A rewrite was defined with both `basePath: false` and an internal `destination`. Rewrites that capture urls outside of the `basePath` must route externally, as they are intended for proxying in the case of incremental adoption of Next.js in a project.

#### Possible Ways to Fix It

Look for any rewrite where `basePath` is `false` and make sure its `destination` starts with `http://` or `https://`.

### Useful Links

- [Rewrites section in Documentation](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
11 changes: 11 additions & 0 deletions examples/auth0/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Public Environment variables that can be used in the browser.
NEXT_PUBLIC_AUTH0_CLIENT_ID=
NEXT_PUBLIC_AUTH0_SCOPE="openid profile"
NEXT_PUBLIC_AUTH0_DOMAIN=
NEXT_PUBLIC_REDIRECT_URI="http://localhost:3000/api/callback"
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI="http://localhost:3000"

# Secret environment variables only available to Node.js
AUTH0_CLIENT_SECRET=
SESSION_COOKIE_SECRET=
SESSION_COOKIE_LIFETIME=7200
6 changes: 0 additions & 6 deletions examples/auth0/.env.template

This file was deleted.

3 changes: 0 additions & 3 deletions examples/auth0/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# auth0 env
.env

# local env files
.env.local
.env.development.local
Expand Down
85 changes: 24 additions & 61 deletions examples/auth0/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Next.js and Auth0 Example

This example shows how you can use `@auth0/nextjs-auth` to easily add authentication support to your Next.js application.
This example shows how you can use `@auth0/nextjs-auth` to easily add authentication support to your Next.js application. It tries to cover a few topics:

- Signing in
- Signing out
- Loading the user on the server side and adding it as part of SSR ([`pages/advanced/ssr-profile.js`](pages/advanced/ssr-profile.js))
- Loading the user on the client side and using fast/cached SSR pages ([`pages/index.js`](pages/index.js))
- API Routes which can load the current user ([`pages/api/me.js`](pages/api/me.js))
- Using hooks to make the user available throughout the application ([`lib/user.js`](lib/user.js))

Read more: [https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/](https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/)

### Using `create-next-app`
## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

Expand All @@ -25,76 +32,32 @@ yarn create next-app --example auth0 auth0

4. Save the settings

### Configuring Next.js

In the Next.js configuration file (`next.config.js`) you'll see that different environment variables are being assigned.

### Local Development
### Set up environment variables

For local development you'll want to create a `.env` file with the necessary settings.
To connect the app with Auth0, you'll need to add the settings from your Auth0 application as environment variables

The required settings can be found on the Auth0 application's settings page:
Copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git):

```
AUTH0_DOMAIN=YOUR_AUTH0_DOMAIN
AUTH0_CLIENT_ID=YOUR_AUTH0_CLIENT_ID
AUTH0_CLIENT_SECRET=YOUR_AUTH0_CLIENT_SECRET
SESSION_COOKIE_SECRET=viloxyf_z2GW6K4CT-KQD_MoLEA2wqv5jWuq4Jd0P7ymgG5GJGMpvMneXZzhK3sL (at least 32 characters, used to encrypt the cookie)
REDIRECT_URI=http://localhost:3000/api/callback
POST_LOGOUT_REDIRECT_URI=http://localhost:3000/
```bash
cp .env.local.example .env.local
```

### Hosting on Vercel

When deploying this example to Vercel you'll want to update the `vercel.json` configuration file.

```json
{
"build": {
"env": {
"AUTH0_DOMAIN": "YOUR_AUTH0_DOMAIN",
"AUTH0_CLIENT_ID": "YOUR_AUTH0_CLIENT_ID",
"AUTH0_CLIENT_SECRET": "@auth0_client_secret",
"REDIRECT_URI": "https://my-website.now.sh/api/callback",
"POST_LOGOUT_REDIRECT_URI": "https://my-website.now.sh/",
"SESSION_COOKIE_SECRET": "@session_cookie_secret",
"SESSION_COOKIE_LIFETIME": 7200
}
}
}
```
Then, open `.env.local` and add the missing environment variables:

- `AUTH0_DOMAIN` - Can be found in the Auth0 dashboard under `settings`.
- `AUTH0_CLIENT_ID` - Can be found in the Auth0 dashboard under `settings`.
- `NEXT_PUBLIC_AUTH0_DOMAIN` - Can be found in the Auth0 dashboard under `settings`.
- `NEXT_PUBLIC_AUTH0_CLIENT_ID` - Can be found in the Auth0 dashboard under `settings`.
- `AUTH0_CLIENT_SECRET` - Can be found in the Auth0 dashboard under `settings`.
- `REDIRECT_URI` - The url where Auth0 redirects back to, make sure a consistent url is used here.
- `POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out
- `NEXT_PUBLIC_REDIRECT_URI` - The url where Auth0 redirects back to, make sure a consistent url is used here.
- `NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out
- `SESSION_COOKIE_SECRET` - A unique secret used to encrypt the cookies, has to be at least 32 characters. You can use [this generator](https://generate-secret.now.sh/32) to generate a value.
- `SESSION_COOKIE_LIFETIME` - How long a session lasts in seconds. The default is 2 hours.

The `@auth0_client_secret` and `@session_cookie_secret` are [Vercel environment secrets](https://vercel.com/docs/v2/environment-variables-and-secrets/)
## Deploy on Vercel

You can create the `@auth0_client_secret` by running:
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

```
now secrets add auth0_client_secret PLACE_YOUR_AUTH0_CLIENT_SECRET
```

And create the `session_cookie_secret` by generating a value [here](https://generate-secret.now.sh/32) and running:
### Deploy Your Local Project

```
now secrets add session_cookie_secret PLACE_YOUR_SESSION_COOKIE_SECRET
```
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example).

## About this sample

This sample tries to cover a few topics:

- Signing in
- Signing out
- Loading the user on the server side and adding it as part of SSR (`/pages/advanced/ssr-profile.js`)
- Loading the user on the client side and using fast/cached SSR pages (`/pages/index.js`)
- API Routes which can load the current user (`/pages/api/me.js`)
- Using hooks to make the user available throughout the application (`/lib/user.js`)
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.
21 changes: 12 additions & 9 deletions examples/auth0/lib/auth0.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { initAuth0 } from '@auth0/nextjs-auth0'
import config from './config'

export default initAuth0({
clientId: config.AUTH0_CLIENT_ID,
clientSecret: config.AUTH0_CLIENT_SECRET,
scope: config.AUTH0_SCOPE,
domain: config.AUTH0_DOMAIN,
redirectUri: config.REDIRECT_URI,
postLogoutRedirectUri: config.POST_LOGOUT_REDIRECT_URI,
clientId: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
scope: process.env.NEXT_PUBLIC_AUTH0_SCOPE || 'openid profile',
domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN,
redirectUri:
process.env.NEXT_PUBLIC_REDIRECT_URI ||
'http://localhost:3000/api/callback',
postLogoutRedirectUri:
process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI ||
'http://localhost:3000/',
session: {
cookieSecret: config.SESSION_COOKIE_SECRET,
cookieLifetime: config.SESSION_COOKIE_LIFETIME,
cookieSecret: process.env.SESSION_COOKIE_SECRET,
cookieLifetime: Number(process.env.SESSION_COOKIE_LIFETIME) || 7200,
},
})
26 changes: 0 additions & 26 deletions examples/auth0/lib/config.js

This file was deleted.

17 changes: 0 additions & 17 deletions examples/auth0/next.config.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/auth0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"license": "MIT",
"dependencies": {
"@auth0/nextjs-auth0": "^0.6.0",
"dotenv": "^8.2.0",
"next": "latest",
"react": "^16.12.0",
"react-dom": "^16.12.0"
Expand Down
12 changes: 0 additions & 12 deletions examples/auth0/vercel.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/with-apollo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

In this simple example, we integrate Apollo seamlessly with [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching) to fetch queries in the server and hydrate them in the browser.

This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend.
This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.

## Demo

Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo/components/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PostUpvoter from './PostUpvoter'

export const ALL_POSTS_QUERY = gql`
query allPosts($first: Int!, $skip: Int!) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
allPosts(orderBy: { createdAt: desc }, first: $first, skip: $skip) {
id
title
votes
Expand Down
9 changes: 4 additions & 5 deletions examples/with-apollo/components/PostUpvoter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { gql, useMutation } from '@apollo/client'

const UPDATE_POST_MUTATION = gql`
mutation updatePost($id: ID!, $votes: Int) {
updatePost(id: $id, votes: $votes) {
__typename
mutation votePost($id: String!) {
votePost(id: $id) {
id
votes
__typename
}
}
`
Expand All @@ -17,11 +17,10 @@ export default function PostUpvoter({ votes, id }) {
updatePost({
variables: {
id,
votes: votes + 1,
},
optimisticResponse: {
__typename: 'Mutation',
updatePost: {
votePost: {
__typename: 'Post',
id,
votes: votes + 1,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo/components/Submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Submit() {
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
})
// Update the cache with the new post at the top of the
// Update the cache with the new post at the top of the list
proxy.writeQuery({
query: ALL_POSTS_QUERY,
data: {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo/lib/apolloClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === 'undefined',
link: new HttpLink({
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute)
uri: 'https://nextjs-graphql-with-prisma-simple.vercel.app/api', // Server URL (must be absolute)
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
}),
cache: new InMemoryCache({
Expand Down
Loading

0 comments on commit c8b8308

Please sign in to comment.