-
-
Notifications
You must be signed in to change notification settings - Fork 186
Feature: Option to remove server side auth #610
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
Merged
phoenix-ru
merged 37 commits into
sidebase:main
from
KyleSmith0905:option-to-remove-server
Apr 18, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
d7148df
feat: Added option to remove server
KyleSmith0905 acc827d
Merge branch 'sidebase:main' into option-to-remove-server
KyleSmith0905 a85d3bf
lint: remove extra semicolon.
KyleSmith0905 d255810
docs: Added disableServerSideAuth to Nuxt Config docs.
KyleSmith0905 e6c1251
doc: Added consistent spacing in disableServerSideAuth JSDoc.
KyleSmith0905 21ec51e
Added route-based rules for cache-support.
KyleSmith0905 53e82fd
Merge pull request #1 from KyleSmith0905/use-nuxt-route-rules
KyleSmith0905 91d8da5
Made port a variable on nuxt config base url.
KyleSmith0905 66de79d
Capitalize PORT on Authjs Playground Nuxt Config (oops, I hope this f…
KyleSmith0905 6671ea5
Change `playground-authjs` CI port to 3000.
KyleSmith0905 4bc4de3
Merge branch 'option-to-remove-server' of https://github.com/KyleSmit…
KyleSmith0905 e040030
Merge branch 'main' into option-to-remove-server
zoey-kaiser acf4777
Merge branch 'main' into option-to-remove-server
zoey-kaiser 86ffbae
Merge branch 'main' into option-to-remove-server
zoey-kaiser 559a0ae
Remove cache on a route that wasn't supposed to be cached
KyleSmith0905 cce8fd6
Merge branch 'main' of https://github.com/sidebase/nuxt-auth into opt…
KyleSmith0905 9cb0b73
Store route matcher between sessions.
KyleSmith0905 e507404
fix: Typo referencing token when retrieving cookie.
KyleSmith0905 f89f85a
fix(docs): Typo with incorrect spelling of false in route config page
KyleSmith0905 98afc89
Merge branch 'option-to-remove-server' of https://github.com/KyleSmit…
KyleSmith0905 eccff95
fix(playground): Fixed created at variable being used for cached at.
KyleSmith0905 139efdc
Merge branch 'option-to-remove-server' of https://github.com/KyleSmit…
KyleSmith0905 68d84f5
fix(docs): Clarified what disable server side fetching does behind th…
KyleSmith0905 cc042f5
fix(docs): Added JSDoc example and fix misspelling on route rules types.
KyleSmith0905 8ac22da
fix(docs): Clarified that global setting results in caching.
KyleSmith0905 6c10a9a
Merge branch 'option-to-remove-server' of https://github.com/KyleSmit…
KyleSmith0905 9843c30
fix(playground): On SWR pages, display time.
KyleSmith0905 48f7425
fix: Fixed route rules incorrectly referenced.
KyleSmith0905 59a663c
fix: import from `#import` in route matcher to fix CI error
KyleSmith0905 15f134f
fix: import from `#import` in route matcher to fix CI error
KyleSmith0905 2219da7
Merge branch 'option-to-remove-server' of https://github.com/KyleSmit…
KyleSmith0905 dfb2ac7
Merge branch 'main' into option-to-remove-server
zoey-kaiser 10f1307
fix: Prevent auth from route rules from erroring when undefined.
KyleSmith0905 08160bf
fix: Reverted CI changes.
KyleSmith0905 0d0a167
fix(CI): Add env variable to AuthJS example on build.
KyleSmith0905 24a4ab4
Merge branch 'main' into option-to-remove-server
zoey-kaiser 0f8baa5
Merge branch 'main' into option-to-remove-server
phoenix-ru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| description: "Learn how to configure your project to support caching" | ||
| --- | ||
|
|
||
| ::alert{type="info"} | ||
| If you are using the following routeRules (`swr`, `isr`, `prerender`), you will need to read this. When prerendering your entire site using `nuxi generate`, this is done automatically. | ||
| :: | ||
|
|
||
| # Caching Content | ||
|
|
||
| Often hosting providers offer caching on the edge. Most websites can experience incredible speeds (and cost savings) by taking advantage of caching. No cold start, no processing requests, no parsing Javascript... just HTML served immediately from a CDN. | ||
|
|
||
| By default we send the user's authentication data down to the client in the HTML. This might not be ideal if you're caching your pages. Users may be able to see other user's authentication data if not handled properly. | ||
|
|
||
| To add caching to your Nuxt app, follow the [Nuxt documentation on hybrid rendering](https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering). | ||
|
|
||
| ## Configuration | ||
|
|
||
| ::alert{type="warning"} | ||
| If you find yourself needing to server-rendered auth methods like `getProviders()`, you must set the `baseURL` option on the `auth` object. This applies in development too. | ||
| :: | ||
|
|
||
| ### Page Specific Cache Rules | ||
|
|
||
| If only a few of your pages are cached. Head over to the Nuxt config `routeRules`, add the `auth` key to your cached routes. Set `disableServerSideAuth` to `true`. | ||
|
|
||
| ```ts | ||
| export default defineNuxtConfig({ | ||
| modules: ['@sidebase/nuxt-auth'], | ||
| auth: { | ||
| // Optional - Needed for getProviders() method to work server-side | ||
| baseURL: 'http://localhost:3000', | ||
| }, | ||
| routeRules: { | ||
| '/': { | ||
| swr: 86400000, | ||
| auth: { | ||
| disableServerSideAuth: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Module Cache Rules | ||
|
|
||
| If all/most pages on your site are cached. Head over to the Nuxt config, add the `auth` key if not already there. Set `disableServerSideAuth` to `true`. | ||
|
|
||
| ```ts | ||
| export default defineNuxtConfig({ | ||
| modules: ['@sidebase/nuxt-auth'], | ||
| auth: { | ||
| disableServerSideAuth: true, | ||
| // Optional - Needed for getProviders() method to work server-side | ||
| baseURL: 'http://localhost:3000', | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Combining Configurations | ||
|
|
||
| Route-configured options take precedent over module-configured options. If you disabled server side auth in the module, you may still enable server side auth back by setting `auth.disableServerSideAuth` to `false`. | ||
|
|
||
| For example: It may be ideal to add caching to every page besides your profile page. | ||
|
|
||
| ```ts | ||
| export default defineNuxtConfig({ | ||
| modules: ['@sidebase/nuxt-auth'], | ||
| auth: { | ||
| disableServerSideAuth: true, | ||
| }, | ||
| routeRules: { | ||
| // Server side auth is disabled on this page because of global setting | ||
| '/': { | ||
| swr: 86400000, | ||
| } | ||
| // Server side auth is enabled on this page - route rules takes priority. | ||
| '/profile': { | ||
| auth: { | ||
| disableServerSideAuth: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Route Rules | ||
|
|
||
| Use the `auth`-key inside the `nuxt.config.ts` `routeRules` to configure page-specific settings. | ||
|
|
||
| ```ts | ||
| interface RouteOptions { | ||
| /** | ||
| * Forces your server to send a "loading" status on a route, prompting the client to fetch on the client. If a specific page has caching, this prevents the server from caching someone's authentication status. | ||
| * | ||
| * @default false | ||
| */ | ||
| disableServerSideAuth: boolean; | ||
| } | ||
| ``` |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <script setup lang="ts"> | ||
| import { definePageMeta, ref, useState } from '#imports' | ||
|
|
||
| const clientRenderTime = ref<Date>(new Date()) | ||
|
|
||
| const serverRenderTime = useState('server-render-date', () => new Date()) | ||
|
|
||
| definePageMeta({ auth: false }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <p>Server Render Time: {{ serverRenderTime?.toISOString() }}</p> | ||
| <p>Client Render Time: {{ clientRenderTime?.toISOString() }}</p> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <script setup lang="ts"> | ||
| import { definePageMeta, ref, useState } from '#imports' | ||
|
|
||
| const clientRenderTime = ref<Date>(new Date()) | ||
|
|
||
| const serverRenderTime = useState('server-render-date', () => new Date()) | ||
|
|
||
| definePageMeta({ auth: false }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <p>Server Render Time: {{ serverRenderTime?.toISOString() }}</p> | ||
| <p>Client Render Time: {{ clientRenderTime?.toISOString() }}</p> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <script setup lang="ts"> | ||
| import { definePageMeta, ref, useState } from '#imports' | ||
|
|
||
| const clientRenderTime = ref<Date>(new Date()) | ||
|
|
||
| const serverRenderTime = useState('server-render-date', () => new Date()) | ||
|
|
||
| definePageMeta({ auth: false }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <p>Server Render Time: {{ serverRenderTime?.toISOString() }}</p> | ||
| <p>Client Render Time: {{ clientRenderTime?.toISOString() }}</p> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.