KWAC
KWAC
Explore posts from servers
DTDrizzle Team
Created by KWAC on 7/31/2024 in #help
quering with nuxt + drizzle + cloudflare D1
Here's a snippet from my signup.vue page making api call:
const signupData = {
firstname: this.firstnameSignUp,
lastname: this.lastnameSignUp,
email: this.emailSignUp,
username: this.usernameSignUp,
password: this.passwordSignUp,
confirm_password: this.confirm_password,
country: this.selectedCountry,
gender: this.gender,
phone: this.phone,
selectedPhoneCode: this.selectedPhoneCode,
date_of_birth: this.date_of_birth,
terms: this.terms
};

const response = await fetch('/api/login/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(signupData)
});

const result = await response.json();

if (!result.success) {
this.errors = result.errors;
} else {
await navigateTo('/verify');
}
const signupData = {
firstname: this.firstnameSignUp,
lastname: this.lastnameSignUp,
email: this.emailSignUp,
username: this.usernameSignUp,
password: this.passwordSignUp,
confirm_password: this.confirm_password,
country: this.selectedCountry,
gender: this.gender,
phone: this.phone,
selectedPhoneCode: this.selectedPhoneCode,
date_of_birth: this.date_of_birth,
terms: this.terms
};

const response = await fetch('/api/login/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(signupData)
});

const result = await response.json();

if (!result.success) {
this.errors = result.errors;
} else {
await navigateTo('/verify');
}
Data is not inserted into a table from api call. But from drizzle kit studio (using D1) I can modify data without problems. Am I doing something wrong here?
3 replies
DTDrizzle Team
Created by KWAC on 7/31/2024 in #help
quering with nuxt + drizzle + cloudflare D1
my api (api/login/signup.post.js) looks like this:
import { generateId } from "lucia";
import { user } from "@/server/db/schema.ts";

export default defineEventHandler(async (event) => {

const lucia = event.context.lucia;
const db = event.context.db;

const body = await readBody(event);

const {
firstname,
lastname,
email,
username,
password,
confirm_password,
country,
gender,
phone,
selectedPhoneCode,
date_of_birth,
terms
} = body;


try{
await db.insert(user).values({
id: userId,
firstname: firstname,
lastname: lastname,
email: email,
username: username,
password: password,
confirm_password: confirm_password,
country: country,
gender: gender,
date_of_birth: date_of_birth,
selectedPhoneCode: selectedPhoneCode,
phone: phone,
created_at: createdAt,
}).run();

const session = await lucia.createSession(userId, {});
appendHeader(event, "Set-Cookie", lucia.createSessionCookie(session.id).serialize());
return { success: true};
} catch (error) {
return { success: false, errors };
}
}

});
import { generateId } from "lucia";
import { user } from "@/server/db/schema.ts";

export default defineEventHandler(async (event) => {

const lucia = event.context.lucia;
const db = event.context.db;

const body = await readBody(event);

const {
firstname,
lastname,
email,
username,
password,
confirm_password,
country,
gender,
phone,
selectedPhoneCode,
date_of_birth,
terms
} = body;


try{
await db.insert(user).values({
id: userId,
firstname: firstname,
lastname: lastname,
email: email,
username: username,
password: password,
confirm_password: confirm_password,
country: country,
gender: gender,
date_of_birth: date_of_birth,
selectedPhoneCode: selectedPhoneCode,
phone: phone,
created_at: createdAt,
}).run();

const session = await lucia.createSession(userId, {});
appendHeader(event, "Set-Cookie", lucia.createSessionCookie(session.id).serialize());
return { success: true};
} catch (error) {
return { success: false, errors };
}
}

});
3 replies