Skip to content

atinux/nuxt-bcrypt-edge

Repository files navigation

Nuxt Bcrypt Edge

A demo of hashing and verifying passwords with bcrypt-edge on Cloudflare Workers with Nuxt and NuxtHub.

https://bcrypt.nuxt.dev

Features

  • Hash & verify a password with bcrypt-edge
  • Also works with Scrypt (no dependency needed)
  • Server-Side rendering on Cloudflare Workers

Setup

Make sure to install the dependencies with pnpm:

pnpm install

Development Server

Start the development server on http://localhost:3000:

pnpm dev

Hashing and Verifying

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 }
});

Production

Build the application for production:

pnpm build

Deploy

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.

About

Example of using Nuxt + Bcrypt on Cloudflare Workers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published