diff --git a/README.md b/README.md index 602a6d6..8f04c6a 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,34 @@ Make sure to set the callback URL in your OAuth app settings as `/a If the redirect URL mismatch in production, this means that the module cannot guess the right redirect URL. You can set the `NUXT_OAUTH__REDIRECT_URL` env variable to overwrite the default one. +### Password Utils + +Nuxt Auth Utils provides a `hashPassword` and `verifyPassword` function to hash and verify passwords by using [scrypt](https://en.wikipedia.org/wiki/Scrypt) as it is supported in many JS runtime. + +```ts +const hashedPassword = await hashPassword('user_password') + +if (await verifyPassword(hashedPassword, 'user_password')) { + // Password is valid +} +``` + +You can configure the scrypt options in your `nuxt.config.ts`: + +```ts +export default defineNuxtConfig({ + modules: ['nuxt-auth-utils'], + auth: { + hash: { + scrypt: { + // See https://github.com/adonisjs/hash/blob/94637029cd526783ac0a763ec581306d98db2036/src/types.ts#L144 + } + } + } +}) +``` + + ### Extend Session We leverage hooks to let you extend the session data with your own data or log when the user clears the session. @@ -414,7 +442,7 @@ npm run release [npm-version-href]: https://npmjs.com/package/nuxt-auth-utils [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-auth-utils.svg?style=flat&colorA=020420&colorB=00DC82 -[npm-downloads-href]: https://npmjs.com/package/nuxt-auth-utils +[npm-downloads-href]: https://npm.chart.dev/nuxt-auth-utils [license-src]: https://img.shields.io/npm/l/nuxt-auth-utils.svg?style=flat&colorA=020420&colorB=00DC82 [license-href]: https://npmjs.com/package/nuxt-auth-utils diff --git a/package.json b/package.json index 75891a5..840cc61 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nuxt-auth-utils", "version": "0.3.9", - "description": "Minimalist Auth module for Nuxt with SSR", + "description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.", "repository": "Atinux/nuxt-auth-utils", "license": "MIT", "type": "module", @@ -32,7 +32,8 @@ "test:watch": "vitest watch" }, "dependencies": { - "@nuxt/kit": "^3.13.2", + "@adonisjs/hash": "^9.0.5", + "@nuxt/kit": "^3.13.0", "defu": "^6.1.4", "hookable": "^5.5.3", "ofetch": "^1.3.4", diff --git a/playground/app.vue b/playground/app.vue index 8f0fbc1..32b89b6 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -8,7 +8,7 @@ const toast = useToast() async function login() { if (logging.value || !password.value) return logging.value = true - await $fetch('/api/login', { + await $fetch('/api/built-in-password', { method: 'POST', body: { password: password.value, @@ -180,13 +180,15 @@ const providers = computed(() =>