Skip to content

Commit

Permalink
Merge branch 'main' into dev-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser authored Oct 11, 2023
2 parents 9050df3 + 6434f53 commit 0eec1d9
Show file tree
Hide file tree
Showing 35 changed files with 6,841 additions and 6,995 deletions.
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 🐞 Bug report
description: Create a bug report for this project
labels: [bug]
body:
- type: markdown
attributes:
value: |
Please help us finding and resolving problems.
- type: textarea
id: bug-env
attributes:
label: Environment
description: You can use `npx nuxi info` to fill this section
placeholder: Environment
- type: textarea
id: reproduction
attributes:
label: Reproduction
description: Provide a link to a repo that can reproduce the problem you ran into if you can.
placeholder: Reproduction
- type: textarea
id: bug-description
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks!
placeholder: Bug description
validations:
required: true
- type: textarea
id: additonal
attributes:
label: Additional context
description: If applicable, add any other context about the problem here
- type: textarea
id: logs
attributes:
label: Logs
description: |
Optional if provided reproduction. Please try not to insert an image but copy paste the log text.
render: shell
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: 📚 nuxt-auth documentation
url: https://sidebase.io/nuxt-auth
about: Check the documentation for usage of nuxt-auth
- name: 💬 Discussions
url: https://github.com/sidebase/nuxt-auth/discussions
about: Use discussions if you have another issue, an idea for improvement or for asking questions.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 🚀 Feature request
description: Suggest a feature to improve this project
labels: [enhancement]
body:
- type: markdown
attributes:
value: |
Thank you for taking the time to fill out this feature request of this young, just growing project. It really means a lot to us! ❤️
- type: textarea
id: feature-description
attributes:
label: Describe the feature
description: A clear and concise description of what you think would be a helpful addition, including the possible use cases and alternatives you have considered. If you have a working prototype or module that implements it, please include a link.
placeholder: Feature description
validations:
required: true
- type: textarea
id: additional-info
attributes:
label: Additional information
description: Additional information that helps us decide how to proceed.
placeholder: Additional information
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ This module also has it's own playground:

#### Testing different Providers

We have one playtground per provider:
We have one playground per provider:
- [`local`](./playground-local)
- [`authjs`](./playground-authjs)

Expand Down
1 change: 1 addition & 0 deletions docs/.nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imports.autoImport=true
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ npx nuxi init docs -t nuxt-themes/docus-starter
Install dependencies:

```bash
yarn install
npm install
```

## Development

```bash
yarn dev
npm dev
```

## Edge Side Rendering
Expand All @@ -31,7 +31,7 @@ Can be deployed to Vercel Functions, Netlify Functions, AWS, and most Node-compa
Look at all the available presets [here](https://nuxt.com/docs/getting-started/deployment#presets).

```bash
yarn build
npm build
```

## Static Generation
Expand All @@ -41,15 +41,15 @@ Use the `generate` command to build your application.
The HTML files will be generated in the .output/public directory and ready to be deployed to any static compatible hosting.

```bash
yarn generate
npm generate
```

## Preview build

You might want to preview the result of your build locally, to do so, run the following command:

```bash
yarn preview
npm preview
```

---
Expand Down
3 changes: 2 additions & 1 deletion docs/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineAppConfig({
// @ts-ignore
docus: {
title: 'My Docs'
title: 'nuxt-auth'
}
})
2 changes: 1 addition & 1 deletion docs/content/2.configuration/2.nuxt-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The `AUTH_ORIGIN` environment variable takes precendence over the `origin` confi
The origin must be set so that `nuxt-auth` can ensure that callbacks for authentication are correct. The `origin` consists out of (up to) 3 parts:
- scheme: `http` or `https`
- host: e.g., `localhost`, `example.org`, `www.sidebase.io`
- port: e.g., `:3000`, `:4444`; leave empty to implicitly set `:80` (this is an internet convention, don't ask)
- port: e.g., `:3000`, `:4444`; leave empty to implicitly set `:80` for http, and `:443` for https (this is an internet convention, don't ask)

For the demo-app at https://nuxt-auth-example.sidebase.io we set the `origin` to `https://nuxt-auth-example.sidebase.io`. If for some reason required, you can explicitly set the `origin` to `http://localhost:3000` to stop `nuxt-auth` from aborting `npm run build` when the origin is unset.

Expand Down
2 changes: 2 additions & 0 deletions docs/content/2.configuration/3.nuxt-auth-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export default NuxtAuthHandler({
```
::

::alert{type="info"}
The `NuxtAuthHandler` accepts [all options that NextAuth.js accepts for its API initialization](https://next-auth.js.org/configuration/options#options). Use this place to configure authentication providers (oauth-Google, credential flow, ...), your `secret`, add callbacks for authentication events, configure a custom logger and more. Read the [`NextAuth.js` docs to see all possible options](https://next-auth.js.org/configuration/options#options).
::

### secret

Expand Down
9 changes: 5 additions & 4 deletions docs/content/3.application-side/4.protecting-pages.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Protecting Pages

`nuxt-auth` offers different approaches to protect pages:

1. Global protection: Protects all pages with manual exceptions
2. Local protection: Protects specific pages
3. Custom middleware: Create your own middleware
Expand Down Expand Up @@ -48,6 +49,7 @@ That's it! Every page of your application will now need authentication for the u
### Disabling the global middleware locally

To disable the global middleware on a specific page only, you can use the [`definePageMeta` macro](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) to turn `auth` off:

```vue
<!-- file: ~/pages/index.vue -->
<template>
Expand All @@ -61,7 +63,6 @@ definePageMeta({ auth: false })

Note: This only works on `pages/`. It notably does not work inside the `app.vue`.


## Local middleware

To protect specific pages with a middleware, you can use the [`definePageMeta` macro](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) to turn `auth` on:
Expand Down Expand Up @@ -101,15 +102,15 @@ Following are examples of both kinds of usage:
export default defineNuxtRouteMiddleware((to) => {
const { status, signIn } = useAuth()

// Return immeadiatly if user is already authenticated
// Return immediately if user is already authenticated
if (status.value === 'authenticated') {
return
}

/**
* We cannot directly call and/or return `signIn` here as `signIn` uses async composables under the hood, leading to "nuxt instance undefined errors", see https://github.com/nuxt/framework/issues/5740#issuecomment-1229197529
*
* So to avoid calling it, we return it immeadiatly.
* So to avoid calling it, we return it immediately.
*/
return signIn(undefined, { callbackUrl: to.path }) as ReturnType<typeof navigateTo>
})
Expand All @@ -124,7 +125,7 @@ export default defineNuxtRouteMiddleware((to) => {

const { status, signIn } = useAuth()

// Return immeadiatly if user is already authenticated
// Return immediately if user is already authenticated
if (status.value === 'authenticated') {
return
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/5.recipes/4.custom-session-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default NuxtAuthHandler({
});
}
},
)}
})
]
... // other config

Expand Down
5 changes: 3 additions & 2 deletions docs/content/v0.6/1.getting-started/3.quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ The local provider does not require any additional steps, as it relies on an alr
So when you call the `signIn` method, the endpoint `/api/auth/login` will be hit with the `username` and `password` you pass as a body-payload. You likely have to modify these parameters to fit to your backend - you can adjust these parameters in your `nuxt.config.ts` using the options [specified here](/nuxt-auth/v0.6/configuration/nuxt-config).

Note: The backend can also be in the same Nuxt 3 application, e.g., have a look at this example in the `nuxt-auth` repository:
- [backend-implementation](https://github.com/sidebase/nuxt-auth/v0.6/tree/main/examples/local/server/api/auth)
- [`nuxt.config.ts` matching this implementation](https://github.com/sidebase/nuxt-auth/v0.6/tree/main/examples/local/nuxt.config.ts)
- [full nuxt app](https://github.com/sidebase/nuxt-auth/tree/main/playground-local)
- its [backend](https://github.com/sidebase/nuxt-auth/tree/main/playground-local/server/api/auth)
- its [`nuxt.config.ts`](https://github.com/sidebase/nuxt-auth/blob/main/playground-local/nuxt.config.ts)

::alert{type="info"}
The linked example-implementation only serves as a starting-point and is not considered to be secure.
Expand Down
23 changes: 20 additions & 3 deletions docs/content/v0.6/2.configuration/2.nuxt-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ModuleOptions {
* `baseURL` can be `undefined` during development but _must_ be set to the combination of origin + path that points to your `NuxtAuthHandler` for production. The origin consists out of:
* - `scheme`: http / https
* - `host`: e.g., localhost, example.org, google.com
* - `port`: _empty_ (implies `:80`), :3000, :8888
* - `port`: _empty_ (implies `:80` for http and `:443` for https), :3000, :8888
*
* The path then is a string like `/path/to/auth/api/endpoint/root`.
*
Expand Down Expand Up @@ -206,7 +206,24 @@ type ProviderLocal = {
* Note: Your backend may reject / expire the token earlier / differently.
*/
maxAgeInSeconds?: number,
}
/**
* The cookie sameSite policy. Can be used as a form of csrf forgery protection. If set to `strict`, the cookie will only be passed with requests to the same 'site'. Typically, this includes subdomains. So, a sameSite: strict cookie set by app.mysite.com will be passed to api.mysite.com, but not api.othersite.com.
*
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
*
* @default 'lax'
* @example 'strict'
*/
sameSiteAttribute?: boolean | 'lax' | 'strict' | 'none' | undefined,
},
/**
* Define an interface for the session data object that `nuxt-auth` expects to receive from the `getSession` endpoint.
*
* @default { id: 'string | number' }
* @example { id: 'string', name: 'string', email: 'string' }
* @advanced_array_example { id: 'string', email: 'string', name: 'string', role: 'admin | guest | account', subscriptions: "{ id: number, status: 'ACTIVE' | 'INACTIVE' }[]" }
*/
sessionDataType?: SessionDataObject,
}
```
```ts [SessionConfig]
Expand Down Expand Up @@ -294,7 +311,7 @@ The `baseURL` must be set so that `nuxt-auth` can ensure that callbacks for auth
The `origin` consists out of (up to) 3 parts:
- scheme: `http` or `https`
- host: e.g., `localhost`, `example.org`, `www.sidebase.io`
- port: e.g., `:3000`, `:4444`; leave empty to implicitly set `:80` (this is an internet convention, don't ask)
- port: e.g., `:3000`, `:4444`; leave empty to implicitly set `:80` for http, and `:443` for https (this is an internet convention, don't ask)

For the demo-app at https://nuxt-auth-example.sidebase.io we set the `origin` to `https://nuxt-auth-example.sidebase.io`. If for some reason required, you can explicitly set the `origin` to `http://localhost:3000` to stop `nuxt-auth` from aborting `npm run build` when the origin is unset.

Expand Down
Loading

0 comments on commit 0eec1d9

Please sign in to comment.