Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nuxt): lucia auth module #80

Merged
merged 68 commits into from
Jan 1, 2024
Merged

feat(nuxt): lucia auth module #80

merged 68 commits into from
Jan 1, 2024

Conversation

productdevbook
Copy link
Member

@productdevbook productdevbook commented Dec 24, 2023

TODO

  • graphql support
  • cli support
  • smart .vue pages and component add (signup, login, forgot-password, github login ...)
  • drizzle support
  • middleware
  • BearerToken support (mobile app)
  • Cookie support

Bugs

image

Description

Lucia Auth Easy to integrate and communicate with other modules.

Linked Issues

Additional context

Drizzle Connect example

test - [projectName]

import { session, user } from 'test/drizzle/schema'

const connect = await pergelTest().drizzle().postgresjs().connect({})

export const auth = pergelTest().lucia().use({
  db: connect,
  options: {
  },
  session,
  user,
})

Server Middleware

test - [projectName]

import { auth } from '#pergel/test/lucia'

export default pergelTest().lucia().definePergelNitroMiddleware({
  lucia: auth,
})

Login

import { Argon2id } from 'oslo/password'
import { auth } from '#pergel/test/lucia'

export default eventHandler(async (event) => {
  const db = await pergelTest().drizzle().postgresjs().connect({})
  const body = await readBody(event)
  const username = body.username
  if (
    typeof username !== 'string'
      || username.length < 3
      || username.length > 31
      || !/^[a-z0-9_-]+$/.test(username)
  ) {
    throw createError({
      message: 'Invalid username',
      statusCode: 400,
    })
  }
  const password = body.password
  if (typeof password !== 'string' || password.length < 6 || password.length > 255) {
    throw createError({
      message: 'Invalid password',
      statusCode: 400,
    })
  }

  const [existingUser] = await db.select()
    .from(tablesTest.user).where(eq(tablesTest.user.username, username)).execute()

  if (!existingUser) {
    throw createError({
      message: 'Incorrect username or password',
      statusCode: 400,
    })
  }

  const validPassword = await new Argon2id().verify(existingUser.password, password)
  if (!validPassword) {
    throw createError({
      message: 'Incorrect username or password',
      statusCode: 400,
    })
  }

  const session = await auth.createSession(existingUser.id, {})
  appendHeader(event, 'Set-Cookie', auth.createSessionCookie(session.id).serialize())
})

productdevbook and others added 30 commits December 24, 2023 17:08
@productdevbook productdevbook marked this pull request as ready for review January 1, 2024 08:21
@productdevbook productdevbook merged commit 422acc8 into main Jan 1, 2024
2 checks passed
@productdevbook productdevbook deleted the feat-lucia-auth branch January 1, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant