You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-features/output-file-tracing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ module.exports = {
34
34
35
35
This will create a folder at `.next/standalone` which can then be deployed on it's own without installing `node_modules`.
36
36
37
-
Additionally, a minimal `server.js` file is also output which can be used instead of `next start`. This minimal server does not handle serving the `static` directory as this should be handled by a CDN instead.
37
+
Additionally, a minimal `server.js` file is also output which can be used instead of `next start`. This minimal server does not copy the `.next/static` directory by default as this should ideally be handled by a CDN instead, although it can be copied to the `standalone` folder manually and the `server.js` file will serve it automatically.
Copy file name to clipboardExpand all lines: docs/api-reference/edge-runtime.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,10 +82,6 @@ The following JavaScript language features are disabled, and **will not work:**
82
82
-[`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval): Evaluates JavaScript code represented as a string
83
83
-[`new Function(evalString)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): Creates a new function with the code provided as an argument
84
84
85
-
The following Web APIs are currently not supported, but will be in the future:
86
-
87
-
-[`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController): Abort one or more Web requests when desired
Copy file name to clipboardExpand all lines: docs/api-reference/next/server.md
+74-2Lines changed: 74 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,13 +70,68 @@ import type { NextFetchEvent } from 'next/server'
70
70
71
71
## NextResponse
72
72
73
-
The `NextResponse` object is an extension of the native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) interface, with the following added methods and properties:
73
+
The `NextResponse` class extends the native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) interface, with the following:
74
+
75
+
### Public methods
76
+
77
+
Public methods are available on an instance of the `NextResponse` class. Depending on your use case, you can create an instance and assign to a variable, then access the following public methods:
74
78
75
79
-`cookies` - An object with the cookies in the `Response`
76
-
-`cookie` - Set a cookie in the `Response`
80
+
-`cookie()` - Set a cookie in the `Response`
81
+
-`clearCookie()` - Accepts a `cookie` and clears it
82
+
83
+
```ts
84
+
import { NextResponse } from'next/server'
85
+
importtype { NextRequest } from'next/server'
86
+
87
+
exportfunction middleware(request:NextRequest) {
88
+
// create an instance of the class to access the public methods. This uses `next()`,
89
+
// you could use `redirect()` or `rewrite()` as well
90
+
let response =NextResponse.next()
91
+
// get the cookies from the request
92
+
let cookieFromRequest =request.cookies['my-cookie']
All methods above return a `NextResponse` object that only takes effect if it's returned in the middleware function.
82
137
@@ -86,6 +141,23 @@ All methods above return a `NextResponse` object that only takes effect if it's
86
141
import { NextResponse } from'next/server'
87
142
```
88
143
144
+
### Setting the cookie before a redirect
145
+
146
+
In order to set the `cookie`_before_ a redirect, you can create an instance of `NextResponse`, then access the `cookie` method on the instance, before returning the response.
147
+
148
+
Note that there is a [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=696204) which means the entire redirect chain **must** be from the same origin, if they are from different origins, then the `cookie` might be missing until a refresh.
149
+
150
+
```ts
151
+
import { NextResponse } from'next/server'
152
+
importtype { NextRequest } from'next/server'
153
+
154
+
exportfunction middleware(req:NextRequest) {
155
+
const res =NextResponse.redirect('/') // creates an actual instance
156
+
res.cookie('hello', 'world') // can be called on an instance
157
+
returnres
158
+
}
159
+
```
160
+
89
161
### Why does redirect use 307 and 308?
90
162
91
163
When using `redirect()` you may notice that the status codes used are `307` for a temporary redirect, and `308` for a permanent redirect. While traditionally a `302` was used for a temporary redirect, and a `301` for a permanent redirect, many browsers changed the request method of the redirect, from a `POST` to `GET` request when using a `302`, regardless of the origins request method.
> **Note**: The `@jest-environment jsdom` comment above configures the testing environment as `jsdom` inside the test file because React Testing Library uses DOM elements like `document.body` which will not work in Jest's default `node` testing environment. Alternatively, you can also set the `jsdom` environment globally by adding the Jest configuration option: `"testEnvironment": "jsdom"` in `jest.config.js`.
460
-
461
-
Optionally, add a [snapshot test](https://jestjs.io/docs/snapshot-testing) to keep track of any unexpected changes to your `<Index />` component:
456
+
Optionally, add a [snapshot test](https://jestjs.io/docs/snapshot-testing) to keep track of any unexpected changes to your `<Home />` component:
This is a [Stytch](https://stytch.com) + [Next.js](https://nextjs.org/) project that showcases how to enable elegant authentication in your applicaiton.
- SDK integration: This flow uses Stytch's React component to create a login and sign-up flow using [Email Magic Links](https://stytch.com/docs/api/send-by-email).
10
+
- API integration: This flow uses a custom UI with Stytch's backend API for [Onetime Passcodes(OTP) via SMS](https://stytch.com/docs/api/sms-otp-overview) authentication.
11
+
12
+
Both flows use Stytch's [Node client library](https://github.com/stytchauth/stytch-node) and [`iron-session`](https://github.com/vvo/next-iron-session) for session management.
13
+
14
+
**Note:** By default this example app enables three of our OAuth providers, Google, Microsoft, and Apple. If you haven't set up these OAuth providers in your [Dashboard](https://stytch.com/dashboard/oauth), you'll receive a redirect error when you attempt to login via those providers. You may remove all OAuth methods by removing `SDKProductTypes.oauth` from the `products` array in [pages/index.tsx](pages/index.tsx) or adjust which ones are displayed by via `oauthOptions.providers` in the same file. More detail on working with OAuth providers in our SDK may be found in our [Docs](https://stytch.com/docs/javascript-sdk#javascript-sdk/oauth).
15
+
16
+
# Deploy on Vercel
17
+
18
+
## Setting up Stytch
19
+
20
+
The first step is to configure the appropriate redirect URLs for your project. You'll set these magic link redirect URLs in the [Redirect URLs](https://stytch.com/dashboard/redirect-urls) section of your Dashboard. Add `https://*.vercel.app:3000` as both a login and sign-up redirect URL.
21
+
22
+
## Running the example app
23
+
24
+
Now just click the deploy button below! Once you're signed in to your Vercel account, you'll be guided through how to get up and running quickly. Check out [.env.template](/.env.template) for pointers on filling in the appropriate environment variables for this step.
25
+
26
+
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch%2F&env=STYTCH_PROJECT_ENV,STYTCH_PROJECT_ID,STYTCH_SECRET,NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN,IRON_SESSION_PASSWORD,IRON_SESSION_COOKIE_NAME&envDescription=All%20variables%20here%20need%20values%2C%20see%20the%20following%20link%20for%20pointers%20on%20how%20to%20feel%20these%20out.&envLink=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch%2F.env.template&project-name=stytch-nextjs-vercel&repo-name=stytch-nextjs-vercel&demo-title=Stytch%20on%20Next.js%20with%20Vercel&demo-description=Next.js%20example%20app%20using%20Stytch%20authentication&demo-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch&demo-image=https%3A%2F%2Fstytch.com%2Flogo-preview.png)
27
+
28
+
# Running locally via `vercel dev`
29
+
30
+
## Setting up Stytch
31
+
32
+
After signing up for Stytch, you'll need your Project's `project_id`, `secret`, and `public_token`. You can find these in the [API keys tab](https://stytch.com/dashboard/api-keys).
33
+
34
+
Once you've gathered these values, add them to a new .env.local file.
35
+
Example:
36
+
37
+
```bash
38
+
cp .env.template .env.local
39
+
# Replace your keys in new .env.local file
40
+
```
41
+
42
+
Next we'll configure the appropriate redirect URLs for your project, you'll set these magic link URLs for your project in the [Redirect URLs](https://stytch.com/dashboard/redirect-urls) section of your Dashboard. Add `http://localhost:3000/api/authenticate_magic_link` as both a login and sign-up redirect URL.
43
+
44
+
## Running the example app
45
+
46
+
Install dependencies by running
47
+
48
+
```bash
49
+
npm install
50
+
# or
51
+
yarn install
52
+
```
53
+
54
+
You can then run a development server using:
55
+
56
+
```bash
57
+
vercel dev
58
+
```
59
+
60
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
61
+
62
+
## Documentation
63
+
64
+
Learn more about some of Stytch's products used in this example app:
0 commit comments