Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Apollo Server and Client Auth Example #9913

Merged
merged 3 commits into from Jan 23, 2020
Merged

Add Apollo Server and Client Auth Example #9913

merged 3 commits into from Jan 23, 2020

Conversation

lifeiscontent
Copy link
Contributor

@lifeiscontent lifeiscontent commented Jan 3, 2020

Add Apollo Server and Client Auth example.

Original conversation with @lfades here #9274

@lifeiscontent
Copy link
Contributor Author

@lfades let me know if you have some better abstractions around the jwt / context passing in the creation of the apollo client. wasn't 100% what to do there, but it works!

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14.1s 13.9s -217ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14.5s 14.2s -263ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: dd8e6ca

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 12.6s 12.9s ⚠️ +219ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 13.1s 13.3s ⚠️ +143ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: 3ff890d

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 11.8s 12.2s ⚠️ +375ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 12.7s 13.1s ⚠️ +353ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: 47cb334

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 13.7s 13.8s ⚠️ +124ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14.1s 14.2s ⚠️ +140ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: 5199e0b

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 12.9s 12.9s -21ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 13.2s 13.3s ⚠️ +38ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: 1e8a6c5

@ijjk
Copy link
Member

ijjk commented Jan 3, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14s 14.1s ⚠️ +29ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.04 kB 1.04 kB
link.html gzip 1.05 kB 1.05 kB
withRouter.html gzip 1.03 kB 1.03 kB
Overall change 3.12 kB 3.12 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14.5s 14.3s -228ms
nodeModulesSize 48.9 MB 48.9 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 6.44 kB 6.44 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..6ef5.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 39.5 kB 39.5 kB
Overall change 69.2 kB 69.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 5.42 kB 5.42 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.6 kB 12.6 kB
framework.HA..dule.js gzip 39.4 kB 39.4 kB
Overall change 63.7 kB 63.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.93 kB 2.93 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.89 kB 9.89 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.49 kB 2.49 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.43 kB 7.43 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 78.9 kB 78.9 kB
hooks.html gzip 1.07 kB 1.07 kB
index.js gzip 79.1 kB 79.1 kB
link.js gzip 81.3 kB 81.3 kB
routerDirect.js gzip 79.2 kB 79.2 kB
withRouter.js gzip 79.3 kB 79.3 kB
Overall change 399 kB 399 kB

Commit: cf922d4

@lfades
Copy link
Member

lfades commented Jan 3, 2020

@lifeiscontent Currently I have mixed feelings about this example, the cookie is not httpOnly, secure (in production) or sameSite, which makes it hard to recommend this example.

I know that the current cookie auth example is like that, and that has to be fixed too before adding another not so secure auth example.

@lifeiscontent
Copy link
Contributor Author

@lfades that's fine, I don't mind updating it. This was only my first pass at the work to get it released :)

@lifeiscontent
Copy link
Contributor Author

lifeiscontent commented Jan 3, 2020

@lfades I copied the with-cookie-auth example, but I'm actually not sure if this is something that would be considered "best practice".

I'd like to understand what the best approach between requests of client / server in next.js would be.

If you'd like I can strictly make the API respond to the authorization header, or make the cookie secure, but I mainly wanted to have a discussion about it with a bunch of you smart people before I do more work on it.

@raduchiriac
Copy link

@lifeiscontent thank you for your time and effort.

I am adding @rkotze (he's maybe unfamiliar with next.js) that might have an interesting input. He wrote a great article about JWT and httpOnly cookies for Apollo here: https://github.com/rkotze/rkotze.github.io/blob/master/_posts/2019-12-02-jwt-secure-apollo-client-graphql.md

My guess is that you should use next-cookie to set the cookies, by maybe updating the res you send inside the WithApollo.getInitialProps

ctx.cookie.set('accessToken', token, {
    path,
    httpOnly: true,
    sameSite: 'Strict',  
    maxAge
})

In that case the HttpLink credentials should also be set to "include" I think.

I might be very wrong about everything I just wrote. I will come back after a more indepth testing.

@lifeiscontent
Copy link
Contributor Author

@raduchiriac great, yeah, I'm not 100% on the protocols for security here either I figured I just put this POC up and have smarter people than me comment on it and then I'll do the work to make it better 👍

@ppot
Copy link

ppot commented Jan 6, 2020

@raduchiriac imao, the auth exemple should just be update with the change needed for an httpOnly Cookie use. As it's different then cookie with Next.

@lfades
Copy link
Member

lfades commented Jan 6, 2020

@lifeiscontent Do this:

  • Use httpOnly always.
  • Set secure to process.env.NODE_ENV === 'production'.
  • Use sameSite.
  • Remove next-cookies. The cookie would be server-only (because of httpOnly), res.setHeader and cookie should be enough

It would not be a state of the class auth method, but it's definitely better.

@lifeiscontent
Copy link
Contributor Author

@lfades sorry for the naivety here, maybe I don't understand something about how the browser/server deals with setting cookies on an HTTP level,

I've updated the login resolve to work as follows:

    async signIn(_parent, args, context, _info) {
      const user = await context.models.User.findOne({
        where: { email: args.input.email },
      })

      if (user && user.validPassword(args.input.password)) {
        const token = context.jwt.sign(
          { email: user.email, id: user.id, time: new Date() },
          context.serverRuntimeConfig.JWT_SECRET,
          {
            expiresIn: '6h',
          }
        )

        const expires = new Date()
        expires.setTime(expires.getTime() + 6 * 60 * 60 * 1000)

        const cookie = Cookie.serialize('token', token, {
          expires,
          httpOnly: true,
          sameSite: true,
          secure: process.env.NODE_ENV === 'production',
          maxAge: 6 * 60 * 60,
        })

        context.res.setHeader('Set-Cookie', cookie)

        return { user, token }
      }

      throw new UserInputError('Invalid email and password combination')
    }

however, when I get the server for a cookie, it seems to have not been set.

e.g. in auth.js:

export const auth = ctx => {
  console.log(ctx.req.headers); // return nothing about a cookie here?
  // const { token } = cookie.parse(ctx.req.headers['cookie'])
  const token = '';

  // If there's no token, it means the user is not signed in.
  if (!token) {
    if (typeof window === 'undefined') {
      ctx.res.writeHead(302, { Location: '/signin' })
      ctx.res.end()
    } else {
      Router.push('/signin')
    }
  }

  return token
}

do you have any idea what I'm doing wrong here?

@lfades
Copy link
Member

lfades commented Jan 14, 2020

@lifeiscontent Follow this example: #9986 - but use Apollo instead of Fauna, the logic should be very similar.

@lifeiscontent
Copy link
Contributor Author

@lfades updated!

@ijjk
Copy link
Member

ijjk commented Jan 14, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 13.6s 13.9s ⚠️ +248ms
nodeModulesSize 49 MB 49 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 5.12 kB 5.12 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..e54b.js gzip 13.7 kB 13.7 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 67.5 kB 67.5 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 4.18 kB 4.18 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.5 kB 12.5 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 62.1 kB 62.1 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.9 kB 2.9 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.87 kB 9.87 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.47 kB 2.47 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.41 kB 7.41 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.02 kB 1.02 kB
link.html gzip 1.03 kB 1.03 kB
withRouter.html gzip 1.01 kB 1.01 kB
Overall change 3.07 kB 3.07 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14.2s 14.4s ⚠️ +168ms
nodeModulesSize 49 MB 49 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 5.12 kB 5.12 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..e54b.js gzip 13.7 kB 13.7 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 67.5 kB 67.5 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 4.18 kB 4.18 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.5 kB 12.5 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 62.1 kB 62.1 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.9 kB 2.9 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.87 kB 9.87 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.47 kB 2.47 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.41 kB 7.41 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 77.8 kB 77.8 kB
hooks.html gzip 1.05 kB 1.05 kB
index.js gzip 78 kB 78 kB
link.js gzip 80.4 kB 80.4 kB
routerDirect.js gzip 78.1 kB 78.1 kB
withRouter.js gzip 78.1 kB 78.1 kB
Overall change 393 kB 393 kB

Commit: 2b01856

@ijjk
Copy link
Member

ijjk commented Jan 14, 2020

Stats from current PR

Default Server Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 13.4s 13.5s ⚠️ +76ms
nodeModulesSize 49 MB 49 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 5.12 kB 5.12 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..e54b.js gzip 13.7 kB 13.7 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 67.5 kB 67.5 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 4.18 kB 4.18 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.5 kB 12.5 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 62.1 kB 62.1 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.9 kB 2.9 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.87 kB 9.87 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.47 kB 2.47 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.41 kB 7.41 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
index.html gzip 1.02 kB 1.02 kB
link.html gzip 1.03 kB 1.03 kB
withRouter.html gzip 1.01 kB 1.01 kB
Overall change 3.07 kB 3.07 kB

Serverless Mode
General
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
buildDuration 14s 14.4s ⚠️ +336ms
nodeModulesSize 49 MB 49 MB
Client Bundles (main, webpack, commons)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.js gzip 5.12 kB 5.12 kB
webpack-HASH.js gzip 746 B 746 B
4952ddcd88e7..54d3.js gzip 4.68 kB 4.68 kB
commons.HASH.js gzip 4.06 kB 4.06 kB
de003c3a9d30..e54b.js gzip 13.7 kB 13.7 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 67.5 kB 67.5 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
main-HASH.module.js gzip 4.18 kB 4.18 kB
webpack-HASH..dule.js gzip 746 B 746 B
4952ddcd88e7..dule.js gzip 5.56 kB 5.56 kB
de003c3a9d30..dule.js gzip 12.5 kB 12.5 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 62.1 kB 62.1 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
polyfills-HASH.js gzip 4.76 kB 4.76 kB
Overall change 4.76 kB 4.76 kB
Client Pages
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.js gzip 1.33 kB 1.33 kB
_error.js gzip 4.07 kB 4.07 kB
hooks.js gzip 779 B 779 B
index.js gzip 222 B 222 B
link.js gzip 2.9 kB 2.9 kB
routerDirect.js gzip 283 B 283 B
withRouter.js gzip 282 B 282 B
Overall change 9.87 kB 9.87 kB
Client Pages Modern
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_app.module.js gzip 757 B 757 B
_error.module.js gzip 3.06 kB 3.06 kB
hooks.module.js gzip 371 B 371 B
index.module.js gzip 212 B 212 B
link.module.js gzip 2.47 kB 2.47 kB
routerDirect..dule.js gzip 273 B 273 B
withRouter.m..dule.js gzip 272 B 272 B
Overall change 7.41 kB 7.41 kB
Client Build Manifests
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles
zeit/next.js canary lifeiscontent/next.js feature/apollo-client-auth Change
_error.js gzip 77.8 kB 77.8 kB
hooks.html gzip 1.05 kB 1.05 kB
index.js gzip 78 kB 78 kB
link.js gzip 80.4 kB 80.4 kB
routerDirect.js gzip 78.1 kB 78.1 kB
withRouter.js gzip 78.1 kB 78.1 kB
Overall change 393 kB 393 kB

Commit: 5dfc446

@lfades
Copy link
Member

lfades commented Jan 15, 2020

@lifeiscontent Looks like I can't run this example in my machine, I'm missing C++ libraries to have sequelize working.

Please add the deploy button (example here) and test it.

Can you confirm that you did what I asked for? it looks like yes, I checked the files and everything looks in order. Also if you can update the readme with the prerequisites that would be awesome too, at least in Windows I know that I need to have python installed and other C++ libraries, if you can use something else that's not sequalize, that can also work. This is an example after all, the easier it can be to run the better.

@lifeiscontent
Copy link
Contributor Author

@lfades I can add a deploy button but I’m pretty sure any library that depends on a DB will require native libraries, I don’t think this is an issue with sequelize but more likely sqlite

@lfades
Copy link
Member

lfades commented Jan 15, 2020

@lifeiscontent If the purpose of the example is to showcase Apollo Server and Auth, whatever DB you choose is not important, a fs based DB could work too.

@lifeiscontent
Copy link
Contributor Author

@lfades that's fair, so what are you suggesting? Should I add the deploy button or should I swap out sequelize for something else?

@lfades
Copy link
Member

lfades commented Jan 16, 2020

@lifeiscontent Is your example, do it as you like, my work here is to make sure that it works properly and other people can use it.

So following that statement, update the README to include good instructions for people who may have issues installing the packages, and add the deploy button and test that it works.

It may be easier to run the example if you switch the db, but that's up to you.

@lifeiscontent
Copy link
Contributor Author

@lfades updated and removed sequelize. Let me know if you need anymore changes.

Also, since the data is in memory, if you edit the code during yarn dev the users you created previously will disappear.

@lifeiscontent
Copy link
Contributor Author

@lfades ping

Copy link
Member

@lfades lfades left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lifeiscontent Looks good to me now, thank you, feel try to use a different storage method, the current one doesn't work well when deployed, maybe a very lightweight db?

@lfades lfades merged commit a356d2f into vercel:canary Jan 23, 2020
@Timer Timer added this to the 9.2.1 milestone Jan 23, 2020
@Timer Timer added the example bug Issue was opened via the example bug report template. label Jan 23, 2020
@antoniojps
Copy link

antoniojps commented Mar 4, 2020

Thanks for this awesome example, using it as a boilerplate for a project I'm working on right now.

Since I had some difficulty trying to figure out how to write a middleware to parse the JWT and inject it into the context or req.user, I thought I'd share how I did it.

Right now to get the current user in a resolver we need to do the following logic everytime:

  1. Parse the token from the cookies
  2. Check if the token is valid and get payload
  3. Fetch user from db I trust JWTs payload, if I need more data from the user then I fetch it
  4. Handle errors
// user resolvers
viewer: async (_parent, _args, context, _info) => {
  // parse the token from the cookies
  const { token } = cookie.parse(context.req.headers.cookie ?? '')
  if (token) {
    try {
      // check if token is valid and get payload
      const { id, email } = jwt.verify(token, JWT_SECRET)
      // fetch user from db
      return users.find(...)
    } catch {
      // handle error
      throw new AuthenticationError('Unauthenticated')
    }
  }
}

I wanted something like this:

// user resolvers
viewer: async (_parent, _args, context, _info) => {
  const { id, email } = context.user
  // rest
}

JWT Middleware to the rescue.

// middleware.js
import cookie from 'cookie'
import jwt from 'jsonwebtoken'
import getConfig from 'next/config'

const { JWT_SECRET, JWT_ISSUER, JWT_AUDIENCE } = getConfig().serverRuntimeConfig

const jwtParser = (handler) => {
  return async (req, res) => {
    let user = null
    const { token } = cookie.parse(req.headers.cookie ?? '')
    if (token) {
      try {
        user = jwt.verify(
          token,
          JWT_SECRET,
          {
            expiresIn: '6h',
            issuer: JWT_ISSUER,
            audience: JWT_AUDIENCE
          }
        )
      } catch {
        user = null
      }
    }
    req.user = user
    return handler(req, res);
  }
}

const middlewareHandler = handler => jwtParser(handler);

export default middlewareHandler;

Then import this to api/graphq.js and export the apolloHandler wrapped with our middleware.

// graphql.js
...

export default middleware(apolloHandler)

Now I can access the user from the context 👇

viewer: (_parent, _args, context, _info) => {
  if (!context.req.user) throw new AuthenticationError('Unauthenticated')
  return context.req.user
}

Here's a boilerplate project based on this example with the implementation of this logic and other juicy stuff like user roles, graphql schema refactoring, database connection middleware (mongoose) and jest tests (soon).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
example bug Issue was opened via the example bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants