-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(nuxt): lucia auth module * Fix waitModule return type in module.ts and update definePergelModule in lucia/index.ts * Add Lucia module to Nuxt config * Fix lucia package installation * lucia types * fix: lint issues * Update user schema and add auto import for PostgresJS driver * fix: lint issues * Refactor database schema and remove unused signup API * Refactor app.vue, user.ts, csvTest.ts, and middleware.ts * lint * Update login page and add error handling for PostgresJS connection * Update dependencies: lucia, @lucia-auth/adapter-drizzle, and @lucia-auth/adapter-postgresql * Update Lucia authentication adapters versions * Add "packages/nuxt/lib" to tsconfig.json exclude list * Add pergel dependency and create download template * Remove default branch value in createDownloadTemplate function * Add support for downloading auth pages template * Update Pergel configuration and file structure * Update file paths in eslint.config.js and auth-pages.mjs * Update file paths in eslint.config.js * version(nuxt): release 0.5.0-beta.0 * Update package.json and auth-pages.mjs * version(nuxt): release 0.5.0-beta.1 * Add UI support to rocket project in nuxt.config.ts and update @pergel/nuxt version to 0.5.0-beta.1 in package.json * Update package versions in examples and playground * Refactor createDownloadTemplate function * version(nuxt): release 0.5.0-beta.2 * fix: lint issues * version(nuxt): release 0.5.0-beta.3 * Fix module validation and update createDownloadTemplate function * version(nuxt): release 0.5.0-beta.4 * version(nuxt): release 0.5.0-beta.5 * Remove waitModule dependency in SES module * version(nuxt): release 0.5.0-beta.6 * Update dependencies and versions * Update Pergel and Lucia modules * version(nuxt): release 0.5.0-beta.7 * fix: lint issues * Delete unused files and update dependencies * Fix UI module dependencies and add consola logger * version(nuxt): release 0.5.0-beta.8 * fix: lint issues * version(nuxt): release 0.5.0-beta.9 * version(nuxt): release 0.5.0-beta.10 * Update version and import statement in UI module * version(nuxt): release 0.5.0-beta.11 * Update dependencies and fix module setup * version(nuxt): release 0.5.0-beta.12 * Refactor definePergelModule to handle missing dependencies * version(nuxt): release 0.5.0-beta.13 * Refactor createDownloadTemplate function * Add DefineDownloadOptions interface to module.ts * Update package.json and README.yaml, delete auth-pages.mjs, and modify createDownloadTemplate.ts * version(nuxt): release 0.5.0-beta.14 * version(nuxt): release 0.5.0-beta.15 * Update pergel version to 0.5.0-beta.14
- Loading branch information
1 parent
8ec382d
commit 422acc8
Showing
42 changed files
with
1,220 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,4 +62,5 @@ lib | |
dist | ||
pergel | ||
schema.graphql | ||
!src/**/pergel | ||
!src/**/pergel | ||
!playground/pergel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "0.1.0", | ||
"templates": { | ||
"pergel-auth": { | ||
"version": "1.0.0", | ||
"branch": "main", | ||
"folder": [ | ||
{ | ||
"dir": "packages/nuxt/playground/pages/auth", | ||
"output": "pages/auth" | ||
} | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
17 changes: 2 additions & 15 deletions
17
packages/nuxt/playground/pergel/test/drizzle/schema/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,2 @@ | ||
// Pergel auto generated please change this file as you wish | ||
import { pgTable, uuid, varchar } from 'drizzle-orm/pg-core' | ||
import { defaultUserSchema } from '@pergel/nuxt/drizzle/schema/pg' | ||
import { sql } from 'drizzle-orm' | ||
|
||
export const user = pgTable('user', { | ||
...defaultUserSchema, | ||
}) | ||
|
||
export const hello = pgTable('hello', { | ||
id: uuid('id').primaryKey().default(sql`uuid_generate_v4()`), | ||
email: varchar('email').unique().notNull(), | ||
password: varchar('password').notNull(), | ||
name: varchar('name').notNull(), | ||
}) | ||
export * from './session' | ||
export * from './user' |
23 changes: 23 additions & 0 deletions
23
packages/nuxt/playground/pergel/test/drizzle/schema/session.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { relations } from 'drizzle-orm' | ||
import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core' | ||
import { user } from './user' | ||
|
||
export const session = pgTable('session', { | ||
id: text('id').primaryKey(), | ||
expiresAt: timestamp('expiresAt', { | ||
withTimezone: true, | ||
mode: 'date', | ||
}).notNull(), | ||
userId: uuid('userId').notNull() | ||
.references(() => user.id), | ||
}) | ||
|
||
export const sessionRelation = relations(session, ({ one }) => ({ | ||
user: one(user, { | ||
fields: [session.userId], | ||
references: [user.id], | ||
}), | ||
})) | ||
|
||
export type Session = (typeof session)['$inferSelect'] | ||
export type SessionInsert = (typeof session)['$inferInsert'] |
31 changes: 31 additions & 0 deletions
31
packages/nuxt/playground/pergel/test/drizzle/schema/user.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { relations, sql } from 'drizzle-orm' | ||
import { pgEnum, pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core' | ||
import { session } from './session' | ||
|
||
export const roleEnum = pgEnum('role', ['user', 'admin', 'userAdmin']) | ||
|
||
export const user = pgTable('user', { | ||
id: uuid('id').primaryKey().default(sql`uuid_generate_v4()`), | ||
name: text('name'), | ||
email: text('email'), | ||
username: text('username').notNull().unique(), | ||
password: text('password').notNull(), | ||
provider: text('provider'), | ||
providerId: text('providerId'), | ||
role: roleEnum('role').notNull().default('user'), | ||
createdAt: timestamp('createdAt', { | ||
withTimezone: true, | ||
mode: 'date', | ||
}).notNull(), | ||
updatedAt: timestamp('updatedAt', { | ||
withTimezone: true, | ||
mode: 'date', | ||
}).notNull(), | ||
}) | ||
|
||
export const userRelation = relations(user, ({ many }) => ({ | ||
sessions: many(session), | ||
})) | ||
|
||
export type User = (typeof user)['$inferSelect'] | ||
export type UserInsert = (typeof user)['$inferInsert'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Session, User } from 'test/drizzle/schema' | ||
import type { auth } from '#pergel/test/lucia' | ||
|
||
declare module 'lucia' { | ||
interface Register { | ||
Lucia: typeof auth | ||
} | ||
interface DatabaseUserAttributes extends Omit<User, 'id'> {} | ||
|
||
interface DatabaseSessionAttributes { | ||
} | ||
} | ||
|
||
declare module 'h3' { | ||
interface H3EventContext { | ||
user: User | null | ||
session: Session | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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()) | ||
}) |
Oops, something went wrong.