migrate to use node due to bun having too many issues (still using bun install)

main
TZGyn 1 year ago
parent 13159e8cf9
commit 2b98daead9
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,4 +1,4 @@
FROM oven/bun:1.1.20 FROM node:22
WORKDIR /app WORKDIR /app
@ -8,14 +8,15 @@ COPY ./bun.lockb ./
COPY . . COPY . .
# COPY ./.env.example ./.env # COPY ./.env.example ./.env
RUN bun install RUN npm install
ARG DATABASE_URL ARG DATABASE_URL
RUN DATABASE_URL=$DATABASE_URL bun run db:migrate RUN DATABASE_URL=$DATABASE_URL npm run db:migrate
RUN bun run build RUN npm run build
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["bun", "--bun", "run", "build"] ENTRYPOINT ["node", "build"]

Binary file not shown.

@ -41,9 +41,11 @@
"dependencies": { "dependencies": {
"@lucia-auth/adapter-drizzle": "^1.0.7", "@lucia-auth/adapter-drizzle": "^1.0.7",
"@prgm/sveltekit-progress-bar": "^2.0.0", "@prgm/sveltekit-progress-bar": "^2.0.0",
"@stripe/stripe-js": "^4.3.0",
"@types/he": "^1.2.3", "@types/he": "^1.2.3",
"apexcharts": "^3.44.0", "apexcharts": "^3.44.0",
"arctic": "^1.9.2", "arctic": "^1.9.2",
"argon2": "^0.41.0",
"bits-ui": "^0.21.13", "bits-ui": "^0.21.13",
"clsx": "^2.0.0", "clsx": "^2.0.0",
"cmdk-sv": "^0.0.13", "cmdk-sv": "^0.0.13",
@ -59,6 +61,7 @@
"postgres": "^3.4.3", "postgres": "^3.4.3",
"qr-code-styling": "^1.6.0-rc.1", "qr-code-styling": "^1.6.0-rc.1",
"resend": "^3.4.0", "resend": "^3.4.0",
"stripe": "^16.8.0",
"svelte-sonner": "^0.3.10", "svelte-sonner": "^0.3.10",
"sveltekit-superforms": "^2.12.2", "sveltekit-superforms": "^2.12.2",
"tailwind-merge": "^2.0.0", "tailwind-merge": "^2.0.0",

@ -2,7 +2,7 @@ import { drizzle } from 'drizzle-orm/postgres-js'
import { migrate } from 'drizzle-orm/postgres-js/migrator' import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres' import postgres from 'postgres'
const sql = postgres(Bun.env.DATABASE_URL ?? '', { max: 1 }) const sql = postgres(process.env.DATABASE_URL ?? '', { max: 1 })
const db = drizzle(sql) const db = drizzle(sql)
await migrate(db, { migrationsFolder: 'drizzle' }) await migrate(db, { migrationsFolder: 'drizzle' })

@ -11,6 +11,7 @@ import { project, shortener, user, visitor } from '$lib/db/schema'
import { eq, inArray } from 'drizzle-orm' import { eq, inArray } from 'drizzle-orm'
import { lucia } from '$lib/server/auth' import { lucia } from '$lib/server/auth'
import { env } from '$env/dynamic/private' import { env } from '$env/dynamic/private'
import * as argon2 from 'argon2'
export const load = (async (event) => { export const load = (async (event) => {
return { return {
@ -41,18 +42,24 @@ export const actions: Actions = {
return setError(form, 'old_password', 'User Not Found') return setError(form, 'old_password', 'User Not Found')
} }
const passwordMatch = await Bun.password.verify( if (!userData.password) {
form.data.old_password, return setError(
form,
'old_password',
'User is using other login method',
)
}
const passwordMatch = await argon2.verify(
userData.password, userData.password,
form.data.old_password,
) )
if (!passwordMatch) { if (!passwordMatch) {
return setError(form, 'old_password', 'Old Password Not Match') return setError(form, 'old_password', 'Old Password Not Match')
} }
const newPassword = await Bun.password.hash( const newPassword = await argon2.hash(form.data.new_password)
form.data.new_password,
)
await db await db
.update(user) .update(user)
@ -94,9 +101,37 @@ export const actions: Actions = {
return setError(form, 'password', 'User Not Found') return setError(form, 'password', 'User Not Found')
} }
const passwordMatch = await Bun.password.verify( if (userData.googleId) {
form.data.password, await lucia.invalidateUserSessions(userId)
await db.delete(user).where(eq(user.id, userId))
const shorteners = await db
.delete(shortener)
.where(eq(shortener.userId, userId))
.returning()
await db.delete(project).where(eq(project.userId, userId))
await db.delete(visitor).where(
inArray(
visitor.shortenerId,
shorteners.map((shortener) => shortener.id),
),
)
return {
form,
}
}
if (!userData.password) {
return setError(form, 'password', 'User Not Found')
}
const passwordMatch = await argon2.verify(
userData.password, userData.password,
form.data.password,
) )
if (!passwordMatch) { if (!passwordMatch) {

@ -8,6 +8,7 @@ import { user as userSchema } from '$lib/db/schema'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
import { lucia } from '$lib/server/auth' import { lucia } from '$lib/server/auth'
import { env } from '$env/dynamic/private' import { env } from '$env/dynamic/private'
import * as argon2 from 'argon2'
export const load = (async (event) => { export const load = (async (event) => {
return { return {
@ -44,8 +45,7 @@ export const actions: Actions = {
} }
const matchPassword = const matchPassword =
user && user && (await argon2.verify(user.password, form.data.password))
(await Bun.password.verify(form.data.password, user.password))
if (!user || !matchPassword) { if (!user || !matchPassword) {
return setError(form, 'email', 'Invalid credentials') return setError(form, 'email', 'Invalid credentials')

@ -9,6 +9,7 @@ import { eq } from 'drizzle-orm'
import { lucia } from '$lib/server/auth' import { lucia } from '$lib/server/auth'
import { env } from '$env/dynamic/private' import { env } from '$env/dynamic/private'
import { sendEmailVerification } from '$lib/server/email' import { sendEmailVerification } from '$lib/server/email'
import * as argon2 from 'argon2'
export const load = (async (event) => { export const load = (async (event) => {
return { return {
@ -47,7 +48,7 @@ export const actions: Actions = {
return setError(form, 'email', 'Email Already Exist') return setError(form, 'email', 'Email Already Exist')
} }
const hashedPassword = await Bun.password.hash(form.data.password) const hashedPassword = await argon2.hash(form.data.password)
const returnUsers = await db const returnUsers = await db
.insert(userSchema) .insert(userSchema)
.values({ .values({

Loading…
Cancel
Save