Helix
Helix
Explore posts from servers
PPrisma
Created by Helix on 11/18/2024 in #help-and-questions
Two Schemas but only one will stay generated at a time
Title is pretty explanatory. I have two schemas for different databases but I can run generate for one schema and then the other schema starts to have error lines in vscode, then generating the other schema swaps the errors to the first schema. Any way to fix this it’s pretty annoying.
10 replies
TTCTheo's Typesafe Cult
Created by Helix on 7/28/2024 in #questions
Lucia Auth Question
I have been having some trouble setting up a deep link redirect callback for Lucia Auth, does anyone have any examples or help they could provide? My setup is just the basic lucia auth setup with the email/password login. Nothing has been changed. https://gist.github.com/cnbrown04/ba61a256dcbc23122b99ea0964567fe1
2 replies
TTCTheo's Typesafe Cult
Created by Helix on 7/25/2024 in #questions
Auth Library Suggestions
I’m currently developing a iOS app in Swift and I’m trying to use a WebAuth session, however it seems nextauth does not work with a native swift app. Any suggestions on what to use instead?
10 replies
TTCTheo's Typesafe Cult
Created by Helix on 7/24/2024 in #questions
NextAuth Callbacks
I'm currently trying to implement my nextauth instance in an ios app, but im having some trouble implementing callbacks that pass the session id and user id/token back to the app. I'm currently just using the credentials authOption, but if anyone could point me in the right direction that would be great. Thanks!
export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}

return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "[email protected]",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;

const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});

if (!user?.passwordHash) return null;

const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);

if (!passwordsMatch) return null;

return user;
},
}),
],
};
export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}

return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "[email protected]",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;

const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});

if (!user?.passwordHash) return null;

const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);

if (!passwordsMatch) return null;

return user;
},
}),
],
};
I haven't changed much from the base t3 stack app besides adding the passwordHash functionalities.
9 replies
DTDrizzle Team
Created by Helix on 7/18/2024 in #help
Querying Views
I'm currently trying to query a view, but im getting an error back.
export const runTest1 = async () => {
try {
// Run a query to the jotform_wm_item_file view to return the first 100 items
const results = await db.select().from(sql`${jotform_wm_item_file}`).limit(100);
console.log(results);
} catch (error) {
console.error("Error in Test Case 1:", error);
}
};
export const runTest1 = async () => {
try {
// Run a query to the jotform_wm_item_file view to return the first 100 items
const results = await db.select().from(sql`${jotform_wm_item_file}`).limit(100);
console.log(results);
} catch (error) {
console.error("Error in Test Case 1:", error);
}
};
and
import { text, mysqlView, int, datetime } from "drizzle-orm/mysql-core";

export const jotform_wm_item_file = mysqlView("jotform_wm_item_file", {
submission_id: int("submission_id"),
alecvid: text("alecvid"),
created_on: datetime("created_on"),
});

export const db = drizzle(poolConnection, { schema: { jotform_wm_item_file }, mode: 'default' });
import { text, mysqlView, int, datetime } from "drizzle-orm/mysql-core";

export const jotform_wm_item_file = mysqlView("jotform_wm_item_file", {
submission_id: int("submission_id"),
alecvid: text("alecvid"),
created_on: datetime("created_on"),
});

export const db = drizzle(poolConnection, { schema: { jotform_wm_item_file }, mode: 'default' });
is my code. I'm getting a parse error but im not sure why.
2 replies
DTDrizzle Team
Created by Helix on 7/12/2024 in #help
Data Retrieved As Same Data
I am retrieving some data using an api, and I'm only getting the same number in one column even though the data is different in the database. My database has a column that is default uuid_short(), is this the correct way to do the schema?
export const auditsTable = mysqlTable("audits", {
AUDIT_ID: varchar("AUDIT_ID", { length: 255 })
.primaryKey()
.$default(() => sql`(uuid_short())`),
DATE: date("DATE").notNull(),
user: varchar("user", { length: 255 }).notNull(),
upc: varchar("upc", { length: 255 }).notNull(),
epc: varchar("epc", { length: 255 }).notNull(),
ex_upc: varchar("ex_upc", { length: 255 }).notNull(),
status: tinyint("status").notNull(),
});
export const auditsTable = mysqlTable("audits", {
AUDIT_ID: varchar("AUDIT_ID", { length: 255 })
.primaryKey()
.$default(() => sql`(uuid_short())`),
DATE: date("DATE").notNull(),
user: varchar("user", { length: 255 }).notNull(),
upc: varchar("upc", { length: 255 }).notNull(),
epc: varchar("epc", { length: 255 }).notNull(),
ex_upc: varchar("ex_upc", { length: 255 }).notNull(),
status: tinyint("status").notNull(),
});
2 replies
DTDrizzle Team
Created by Helix on 7/12/2024 in #help
Drizzle and Turso not showing live data.
I'm currently using Drizzle and Turso, and have an api to add data into my database. However, I am only getting the data that was in the table before I added new data. When I view on Turso I see the updated data, and when I view through Drizzle Studio I am also seeing the updated data, however when I try to use my api to see the data it returns old data.
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/db';
import { auditsTable } from '@/db/schema';
import { sql } from 'drizzle-orm';

export const runtime = 'nodejs';

export async function GET(req: NextRequest) {
try {
// Fetch audits with a timeout
const audits = await Promise.race([
db.select().from(auditsTable).all(),
new Promise((_, reject) => setTimeout(() => reject(new Error('Database query timed out')), 5000))
]) as typeof auditsTable.$inferSelect[];

console.log(`Fetched ${audits.length} audits`);

// Add cache control headers to prevent caching
const response = NextResponse.json(audits);
response.headers.set('Cache-Control', 'no-store, max-age=0');

return response;
} catch (error) {
console.error('Error fetching audits:', error);

if (error instanceof Error) {
return NextResponse.json(
{ message: 'Error fetching audits', error: error.message },
{ status: 500 }
);
}

return NextResponse.json({ message: 'Unknown error occurred' }, { status: 500 });
}
}
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/db';
import { auditsTable } from '@/db/schema';
import { sql } from 'drizzle-orm';

export const runtime = 'nodejs';

export async function GET(req: NextRequest) {
try {
// Fetch audits with a timeout
const audits = await Promise.race([
db.select().from(auditsTable).all(),
new Promise((_, reject) => setTimeout(() => reject(new Error('Database query timed out')), 5000))
]) as typeof auditsTable.$inferSelect[];

console.log(`Fetched ${audits.length} audits`);

// Add cache control headers to prevent caching
const response = NextResponse.json(audits);
response.headers.set('Cache-Control', 'no-store, max-age=0');

return response;
} catch (error) {
console.error('Error fetching audits:', error);

if (error instanceof Error) {
return NextResponse.json(
{ message: 'Error fetching audits', error: error.message },
{ status: 500 }
);
}

return NextResponse.json({ message: 'Unknown error occurred' }, { status: 500 });
}
}
This is my api call.
4 replies