Flux Black

Options

SvelteKit Authentication

Libraries

Better-Auth Tutorials

Articles

Adding Better Auth to your Svelte 5 project

Videos

Svelte Kit Authentication with Better Auth and MongoDB (Authentication and Authorization)

Library Installation Commands

Drizzle ORM

npm i drizzle-orm @libsql/client dotenv
npm i -D drizzle-kit tsx

Valibot

npm i valibot

Argon2

npm i argon2

Helper Constants & Functions

Argon2

Import Library

import * as argon2 from 'argon2'

Argon2ID - Configuration Settings

const argon2id_config = {
    type: argon2.argon2id,
    memoryCost: 1024 * 128,
    hashLength: 32,
    saltLength: 16,
    timeCost: 3,
    parallelism: 2,
}

Hash Password

export const hashPassword = async (password: string, config = argon2id_config) => {
  return await argon2.hash(password, config)
}

Verify Password

export const verifyPassword = async (password: string, hash: string) => {
  return await argon2.verify(hash, password, { type: argon2.argon2id })
}

Token Generation & Hashing

Import Library

import * as crypto from "node:crypto"

Generate Session Token

export const generateSessionToken = () => {
    return crypto.randomBytes(32).toString('hex')
}

Hash Session Token

export const hashToken = (token: string) => {
    return crypto.createHash('sha256').update(token).digest('hex')
}
Copyright © FluxKraken — 2025 — All Rights Reserved