{"_id":"@azzam.hanif93/nuauth","_rev":"2-30222e0bbe6537357e6b8f3a57dfa8d8","name":"@azzam.hanif93/nuauth","dist-tags":{"latest":"1.1.111"},"versions":{"1.1.0":{"name":"@azzam.hanif93/nuauth","version":"1.1.0","license":"MIT","_id":"@azzam.hanif93/nuauth@1.1.0","maintainers":[{"name":"azzam.hanif93","email":"azzam.hanif1@gmail.com"}],"dist":{"shasum":"7e79a500aff98437ae62f6dd0a5d705a132bd316","tarball":"https://registry.npmjs.org/@azzam.hanif93/nuauth/-/nuauth-1.1.0.tgz","fileCount":29,"integrity":"sha512-KoyGziUzT4NjafgDAVmJIWXeChNeApWGcvLiK27dPDeWsw5zacK5iMY4KoZC8y2jNhNc7O05yPSPadrVAX0AQw==","signatures":[{"sig":"MEQCID2Duj5M9U8oSgzNsuRc/GQ9TN7nqyOYGkzrhJJZ6dGOAiAD2jIjnSWucCFvuxAkkj/ReHnqHanmmEHzuxsrNAnnSQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":38568},"main":"./dist/module.cjs","type":"module","types":"./dist/types.d.ts","module":"./dist/module.mjs","exports":{".":{"types":"./dist/types.d.ts","import":"./dist/module.mjs","require":"./dist/module.cjs"},"./core":{"types":"./dist/core/index.d.ts","import":"./dist/core/index.mjs"}},"gitHead":"46bc298d375e12e9d5d95c08e6fe8f93b8ae9fae","scripts":{"dev":"nuxi dev playground","fix":"yarn lint --fix","lint":"eslint . --ext .js,.vue,.ts --format pretty","build":"nuxt-module-build build","prepack":"yarn build","dev:build":"nuxi build playground","dev:prepare":"nuxt-module-build build --stub && nuxi prepare playground"},"_npmUser":{"name":"azzam.hanif93","email":"azzam.hanif1@gmail.com"},"_npmVersion":"10.8.2","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href] [![Nuxt][nuxt-src]][nuxt-href]","directories":{},"_nodeVersion":"20.18.0","dependencies":{"h3":"^1.6.4","ufo":"^1.0.1","defu":"^6.1.2","destr":"^2.0.0","ohash":"^1.1.2","requrl":"^3.0.2","@nuxt/kit":"^3.13.2","cookie-es":"^1.0.0","type-fest":"^4.8.2","html-escaper":"^3.0.3","simple-oauth2":"^5.0.0"},"publishConfig":{"access":"public"},"typesVersions":{"*":{"core":["./dist/core/index.d.ts"],"utils":["./dist/utils.d.ts"]}},"_hasShrinkwrap":false,"packageManager":"yarn@4.5.0","devDependencies":{"nuxt":"3.13.2","eslint":"8.57.1","typescript":"5.6.2","@types/node":"20.16.10","@nuxt/schema":"3.13.2","eslint-plugin-n":"16.6.2","eslint-plugin-vue":"9.28.0","@types/html-escaper":"3.0.2","@nuxt/module-builder":"0.8.4","@types/simple-oauth2":"5.0.7","eslint-plugin-import":"2.30.0","eslint-plugin-promise":"6.6.0","eslint-plugin-unicorn":"47.0.0","eslint-formatter-pretty":"5.0.0","eslint-plugin-varspacing":"1.2.2","@typescript-eslint/parser":"5.62.0","@vue/eslint-config-typescript":"13.0.0","@privyid/eslint-config-persona":"0.27.0","eslint-plugin-align-assignments":"1.1.2","@typescript-eslint/eslint-plugin":"5.62.0","eslint-config-standard-with-typescript":"35.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nuauth_1.1.0_1756145335944_0.6751325103921149","host":"s3://npm-registry-packages-npm-production"}},"1.1.111":{"name":"@azzam.hanif93/nuauth","version":"1.1.111","packageManager":"yarn@4.5.0","license":"MIT","type":"module","exports":{".":{"import":"./dist/module.mjs","require":"./dist/module.cjs","types":"./dist/types.d.ts"},"./core":{"import":"./dist/core/index.mjs","types":"./dist/core/index.d.ts"}},"typesVersions":{"*":{"core":["./dist/core/index.d.ts"],"utils":["./dist/utils.d.ts"]}},"main":"./dist/module.cjs","module":"./dist/module.mjs","types":"./dist/types.d.ts","scripts":{"prepack":"yarn build","build":"nuxt-module-build build","dev":"nuxi dev playground","lint":"eslint . --ext .js,.vue,.ts --format pretty","fix":"yarn lint --fix","dev:build":"nuxi build playground","dev:prepare":"nuxt-module-build build --stub && nuxi prepare playground"},"dependencies":{"@nuxt/kit":"^3.13.2","cookie-es":"^1.0.0","defu":"^6.1.2","destr":"^2.0.0","h3":"^1.6.4","html-escaper":"^3.0.3","ohash":"^1.1.2","requrl":"^3.0.2","simple-oauth2":"^5.0.0","type-fest":"^4.8.2","ufo":"^1.0.1"},"devDependencies":{"@nuxt/module-builder":"0.8.4","@nuxt/schema":"3.13.2","@privyid/eslint-config-persona":"0.27.0","@types/html-escaper":"3.0.2","@types/node":"20.16.10","@types/simple-oauth2":"5.0.7","@typescript-eslint/eslint-plugin":"5.62.0","@typescript-eslint/parser":"5.62.0","@vue/eslint-config-typescript":"13.0.0","eslint":"8.57.1","eslint-config-standard-with-typescript":"35.0.0","eslint-formatter-pretty":"5.0.0","eslint-plugin-align-assignments":"1.1.2","eslint-plugin-import":"2.30.0","eslint-plugin-n":"16.6.2","eslint-plugin-promise":"6.6.0","eslint-plugin-unicorn":"47.0.0","eslint-plugin-varspacing":"1.2.2","eslint-plugin-vue":"9.28.0","nuxt":"3.13.2","typescript":"5.6.2"},"publishConfig":{"access":"public"},"_id":"@azzam.hanif93/nuauth@1.1.111","gitHead":"46bc298d375e12e9d5d95c08e6fe8f93b8ae9fae","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href] [![Nuxt][nuxt-src]][nuxt-href]","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Noj1ZQEf0LNT4YoBNNVXmK01WII7wsRTOc933rxVJHL3pMyGPYxCifgTZv2/bNYrWKmgAoj9T2oX2nnOArgDLA==","shasum":"dda1cb58b2d8f96db5cb95dfd6f252eb451300cd","tarball":"https://registry.npmjs.org/@azzam.hanif93/nuauth/-/nuauth-1.1.111.tgz","fileCount":29,"unpackedSize":38659,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAJywFbjkeMelD55zD39SOXehP++8u87g+lHw/ZTj/fmAiEAgfLHCzEUixC4hsx451fybnICXar5GXcxHOk6U4AARBk="}]},"_npmUser":{"name":"azzam.hanif93","email":"azzam.hanif1@gmail.com"},"directories":{},"maintainers":[{"name":"azzam.hanif93","email":"azzam.hanif1@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nuauth_1.1.111_1756146992440_0.5812998009775725"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-25T18:08:55.864Z","modified":"2025-08-25T18:36:32.855Z","1.1.0":"2025-08-25T18:08:56.139Z","1.1.111":"2025-08-25T18:36:32.661Z"},"license":"MIT","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href] [![Nuxt][nuxt-src]][nuxt-href]","maintainers":[{"name":"azzam.hanif93","email":"azzam.hanif1@gmail.com"}],"readme":"# NuAuth\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![License][license-src]][license-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\n> Oauth2 Client for Nuxt\n\n## Compabilities\n\n- Nuxt 3\n\n## Instalation\n\n```\nyarn add --dev @privyid/nuauth\n```\n\nThen, add into `nuxt.config.ts` modules\n\n```ts\nexport default defineNuxtConfig({\n  modules: ['@privyid/nuauth'],\n  build  : { transpile: ['@privyid/nuauth'] },\n})\n```\n\n## Usage\n\n```ts\nimport { useNuAuth } from '@privyid/nuauth/core'\n\nconst {\n  token,\n  isAlmostExpired,\n  login,\n  logout,\n  refresh,\n} = useNuAuth()\n\n// Get Access-Token\ntoken.value\n\n// Redirect to login page\nlogin()\n\n// Redirect to login page, and redirect to /dashboard after success\nlogin('/dashboard')\n\n// Redirect to logout page\nlogout()\n\n// Redirect to logout page, and redirect to /dashboard after success re-login\nlogout('/dashboard')\n\n// Check token is almost expired (15 minutes before Expired Date)\nif (isAlmostExpired(15)) {\n  // Request new token\n  await refresh()\n}\n```\n\n## Configuration\n\nThis module read enviroment variables directly.\n\n| Env Name                 | Default                    | Description                                                                           |\n|--------------------------|----------------------------|---------------------------------------------------------------------------------------|\n| OAUTH_HOST               | -                          | **(Required)** Oauth server's host                                                    |\n| OAUTH_CLIENT_ID          | -                          | **(Required)** Oauth Client ID                                                        |\n| OAUTH_CLIENT_SECRET      | -                          | **(Required)** Oauth Client Secret                                                    |\n| OAUTH_REDIRECT_URI       | `/auth/callback`           | Oauth Callback URI                                                                    |\n| OAUTH_SCOPE              | `public read`              | Oauth scope                                                                           |\n| OAUTH_LOGOUT_URI         | -                          | Oauth Logout URI                                                                      |\n| OAUTH_HOME               | `/`                        | Redirect path after success login                                                     |\n| OAUTH_REGISTER           | `false`                    | Add params register to Oauth Server                                                   |\n| OAUTH_REDIRECT_WHITELIST | -                          | Redirect path after success login whitelist, for multiple value, use `;` as delimeter |\n| OAUTH_DENIED_REDIRECT    | `Same as OAUTH_HOME`       | Redirect path after user after denying the authorization request                      |\n| OAUTH_AUTHORIZE_PATH     | `/oauth/authorize`         | URL path to request an authorization code                                             |\n| OAUTH_TOKEN_PATH         | `/oauth/token`             | URL path to obtain access tokens                                                      |\n| OAUTH_REVOKE_PATH        | `/oauth/revoke`            | URL path to revoke access tokens                                                      |\n| OAUTH_REFRESH_PATH       | `Same as OAUTH_TOKEN_PATH` | URL path to refresh access tokens                                                     |\n\n👉 See [.env.example](/.env.example) for example\n\n## Cookie Serialize Config\n\nYou can change default cookie config. Add this in your `nuxt.config.ts`\n\n```ts\nexport default defineNuxtConfig({\n  // ...\n  nuauth : {\n    // ...\n    cookie: {\n      httpOnly: true,\n      sameSite: 'none',\n      path    : '/',\n      secure  : true,\n    },\n    // ...\n  }\n})\n```\n\n👉 See [here](https://github.com/jshttp/cookie#options-1) for all cookie options.\n\n## Multiple Server Profile\n\nSince `0.4.0`, you can target more than one oauth server.\n\n1. Add new profile in your `nuxt.config.ts`\n\n```ts\nexport default defineNuxtConfig({\n  // ...\n  nuauth: {\n    // ...\n    profile: {\n      default: 'oauth',\n      names  : [\n        'oauth',  // default profile\n        'github', // additional profile\n      ]\n    }\n    // ...\n  }\n})\n```\n\n2. Your profile's name will become prefix on [config env](#configuration). ex: If your profile's name `github`, your env will became:\n   - `GITHUB_HOST`\n   - `GITHUB_CLIENT_ID`\n   - `GITHUB_CLIENT_SECRET`,\n   - `GITHUB_REDIRECT_URI`\n   - etc.\n\n3. In your component, explicit the profile you want to use.\n\n```ts\nimport { useNuAuth } from '@privyid/nuauth/core'\n\nconst {\n  token,\n  isAlmostExpired,\n  login,\n  logout,\n  refresh,\n} = useNuAuth('github')\n```\n\n## Disable redirection page\n\nTo prevent displaying the redirection page, you can set the sameSite attribute of the cookie to `lax` or `none`.\n\n```js\nexport default defineNuxtConfig({\n  // ...\n  nuauth: {\n    // ...\n    cookie: {\n      sameSite: 'lax', // or 'none' for cross-origin cookies\n    }\n    // ...\n  }\n})\n```\n\n## Middleware Guard\n\nSince `0.7.0`, NuAuth include global middleware which redirect to login page if user not authenticated.\nIf you want disabled it in some page, you can use set meta page `auth` to `false`.\n\n```vue\n<script setup lang=\"ts\">\n  import { definePageMeta } from '#imports'\n\n  definePageMeta({ auth: false })\n</script>\n```\n\nOr you can set auth profile using it\n\n```vue\n<script setup lang=\"ts\">\n  import { definePageMeta } from '#imports'\n\n  definePageMeta({ auth: 'github' })\n</script>\n```\n\nOr if you want disable redirect on every pages:\n\n```ts\n// nuxt.config.ts\n\nexport default defineNuxtConfig({\n  // ...\n  nuauth: {\n    // ...\n    middleware: false,\n    // ...\n  }\n})\n```\n\n## Contribution\n\n- Clone this repository\n- Play [Nyan Cat](https://www.youtube.com/watch?v=QH2-TGUlwu4) in the background (really important!)\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)\n- Run `yarn install`\n- Run `yarn dev:prepare` to generate type stubs.\n- Use `yarn dev` to start [playground](./playground) in development mode.\n\n## License\n\n[MIT License](/LICENSE)\n\n<!-- Badges -->\n[npm-version-src]: https://img.shields.io/npm/v/@privyid/nuauth/latest.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D\n[npm-version-href]: https://npmjs.com/package/@privyid/nuauth\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/@privyid/nuauth.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D\n[npm-downloads-href]: https://npmjs.com/package/@privyid/nuauth\n\n[license-src]: https://img.shields.io/npm/l/@privyid/nuauth.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D\n[license-href]: https://npmjs.com/package/@privyid/nuauth\n\n[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?style=for-the-badge&logo=nuxt.js\n[nuxt-href]: https://nuxt.com\n","readmeFilename":"README.md"}