A demo of hashing and verifying passwords with bcrypt-edge on Cloudflare Workers with Nuxt and NuxtHub.
Make sure to install the dependencies with pnpm:
pnpm install
Start the development server on http://localhost:3000:
pnpm dev
Hashing the password ./server/api/hash.post.ts:
import { hashSync } from 'bcrypt-edge/dist/bcrypt-edge'
export default defineEventHandler(async (event) => {
const { password } = await readBody(event)
const hash = hashSync(password, 10)
return { hash }
});
Verifying the password ./server/api/verify.post.ts:
import { compareSync } from 'bcrypt-edge/dist/bcrypt-edge'
export default defineEventHandler(async (event) => {
const { hash, password } = await readBody(event)
const isValid = compareSync(password, hash)
return { isValid }
});
Build the application for production:
pnpm build
Deploy the application on the Edge with NuxtHub on your Cloudflare account:
npx nuxthub deploy
Then checkout your server logs, analaytics and more in the NuxtHub Admin.
You can also deploy using Cloudflare Pages CI.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.