Eldon
Eldon
TTCTheo's Typesafe Cult
Created by Eldon on 8/21/2024 in #questions
Next.js Use localStorage For Rendering Without Flash?
There has to, or atleast should be, a way to do this completely client side. The server overhead for something so small is not really worth it.
8 replies
TTCTheo's Typesafe Cult
Created by Eldon on 4/18/2024 in #questions
Drizzle Not Working At All On Backend
Just fixed this. I was unaware it is required to use the vercel database for development. I don't like this. To fix this, I used switched to @vercel/postgres and used a development part of the database. This took wayyy too long to figure out.
6 replies
TTCTheo's Typesafe Cult
Created by Eldon on 4/18/2024 in #questions
Drizzle Not Working At All On Backend
also
⨯ Error
at <unknown> (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/1cd2b_@neondatabase_serverless_index_mjs_7c3dee._.js:4307:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async VercelPgPreparedQuery.execute (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/0d925_drizzle-orm_596b94._.js:5657:26)
at async authenticateWithOTP (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/src_e10925._.js:86:17)
at async Object.middleware [as handler] (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/src_e10925._.js:170:9)
at async adapter (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/_e47abe._.js:5063:16)
at async (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/web/sandbox/sandbox.js:110:22)
at async runWithTaggedErrors (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/web/sandbox/sandbox.js:107:9)
at async DevServer.runMiddleware (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js:1060:24)
at async DevServer.runMiddleware (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:268:28) {
name: undefined
⨯ Error
at <unknown> (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/1cd2b_@neondatabase_serverless_index_mjs_7c3dee._.js:4307:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async VercelPgPreparedQuery.execute (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/0d925_drizzle-orm_596b94._.js:5657:26)
at async authenticateWithOTP (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/src_e10925._.js:86:17)
at async Object.middleware [as handler] (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/src_e10925._.js:170:9)
at async adapter (file:///Users/eldonwilliams/crapprojects/eldon-dev/.next/server/edge/chunks/ssr/_e47abe._.js:5063:16)
at async (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/web/sandbox/sandbox.js:110:22)
at async runWithTaggedErrors (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/web/sandbox/sandbox.js:107:9)
at async DevServer.runMiddleware (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js:1060:24)
at async DevServer.runMiddleware (file:///Users/eldonwilliams/crapprojects/eldon-dev/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:268:28) {
name: undefined
is the error message... as I said, unhelpful
6 replies
TTCTheo's Typesafe Cult
Created by Eldon on 4/18/2024 in #questions
Drizzle Not Working At All On Backend
If any more information is needed, let me know Any help would be greatly appreciated, Thank you
6 replies
TTCTheo's Typesafe Cult
Created by Eldon on 4/18/2024 in #questions
Drizzle Not Working At All On Backend
// /src/server/db/authentication.ts

import 'server-only';

import { db } from "./db";
import { authentications } from "./db/schema";
import { generateKey, generateTotpUri, verifyToken } from "authenticator";
import { eq } from 'drizzle-orm';

export async function authenticateWithOTP(otp: string): Promise<boolean> {
otp = otp.replaceAll(" ", "");

console.log(await db.select().from(authentications).where(eq(authentications.active, true)));


return false;
// const key = await db.query.authentications.findFirst({
// where: eq(authentications.active, true),
// columns: {
// key: true,
// }
// }).catch((r) => {
// console.log(r);
// });

// if (key == null) {
// return otp == process.env.STARTER_PASSWORD;
// }

// if (key.key == null) {
// return false;
// }

// const verification = verifyToken(key.key, otp);

// if (verification === null) {
// return false;
// } else {
// return true;
// }
}

export async function generateNewOTPKey(): Promise<string | false> {
return await db.transaction(async (tx) => {
await tx.update(authentications).set({ active: false, }).where(eq(authentications.active, true));
await tx.insert(authentications).values({
active: true,
key: generateKey(),
});
return tx.query.authentications.findFirst({
where: eq(authentications.active as any, true),
columns: {
key: true,
},
});
}).then((key) => {
if (key == null || key.key == null) {
return false;
}
return generateTotpUri(key.key, `Eldon Zone Admin${process.env.NODE_ENV == "development" ? " (DEV)" : ""}`, "", "SHA1", 6, 30);
}).catch(() => {
return false;
});
}
// /src/server/db/authentication.ts

import 'server-only';

import { db } from "./db";
import { authentications } from "./db/schema";
import { generateKey, generateTotpUri, verifyToken } from "authenticator";
import { eq } from 'drizzle-orm';

export async function authenticateWithOTP(otp: string): Promise<boolean> {
otp = otp.replaceAll(" ", "");

console.log(await db.select().from(authentications).where(eq(authentications.active, true)));


return false;
// const key = await db.query.authentications.findFirst({
// where: eq(authentications.active, true),
// columns: {
// key: true,
// }
// }).catch((r) => {
// console.log(r);
// });

// if (key == null) {
// return otp == process.env.STARTER_PASSWORD;
// }

// if (key.key == null) {
// return false;
// }

// const verification = verifyToken(key.key, otp);

// if (verification === null) {
// return false;
// } else {
// return true;
// }
}

export async function generateNewOTPKey(): Promise<string | false> {
return await db.transaction(async (tx) => {
await tx.update(authentications).set({ active: false, }).where(eq(authentications.active, true));
await tx.insert(authentications).values({
active: true,
key: generateKey(),
});
return tx.query.authentications.findFirst({
where: eq(authentications.active as any, true),
columns: {
key: true,
},
});
}).then((key) => {
if (key == null || key.key == null) {
return false;
}
return generateTotpUri(key.key, `Eldon Zone Admin${process.env.NODE_ENV == "development" ? " (DEV)" : ""}`, "", "SHA1", 6, 30);
}).catch(() => {
return false;
});
}
6 replies