Skip to content

qlaffont/elysia-auth-drizzle

Repository files navigation

elysia-auth-drizzle

Library who handle authentification (Header/Cookie/QueryParam).

Usage

import { elysiaAuthDrizzlePlugin } from 'elysia-auth-drizzle';

export const app = new Elysia()
  .use(
      elysiaAuthDrizzlePlugin<typeof users.$inferSelect>({
        config: [
          {
            url: '/public',
            method: 'GET',
          },
        ],
        jwtSecret: 'test',
        drizzle: {
          db: db,
          usersSchema: users,
          tokensSchema: tokens,
        },
      }),
    )

Plugin options

name default description
jwtSecret undefined Secret used to sign JWT
drizzle undefined Contain drizzle db + users schema + tokens schemas ({db, userSchemas, tokenSchemas})
config [] Array who contain url with method allowed in public
cookieSecret undefined (optional) Secret used to sign cookie value
verifyAccessTokenOnlyInJWT false (optional) Check only JWT expiration not token validity in DB
userValidation undefined (optional) (user) => void or Promise<void> / Allow to make more check regarding user (ex: check if user is banned)

Tests

To execute jest tests (all errors, type integrity test)

bun test