Ahm@
Ahm@
NNuxt
Created by Ahm@ on 9/12/2024 in #❓・help
Nuxt /app Pages Not Detecting API Route from /server Directory
when I take everything out of the app folder it works fine, it's weird. when defining the path I tried things like ../ or ~/ but again it didn't work.
15 replies
NNuxt
Created by Ahm@ on 9/12/2024 in #❓・help
Nuxt /app Pages Not Detecting API Route from /server Directory
the new nuxt system includes the contents in the app folder and does not see the server folder in the root folder
15 replies
NNuxt
Created by Ahm@ on 9/12/2024 in #❓・help
Nuxt /app Pages Not Detecting API Route from /server Directory
yes I saved it, I tried rebooting but it didn't work.
15 replies
NNuxt
Created by Ahm@ on 9/12/2024 in #❓・help
Nuxt /app Pages Not Detecting API Route from /server Directory
server/api/auth/register.post.ts file:
import bcrypt from 'bcryptjs';
import { createJWT } from '~/server/utils/jwt';
import User from '~/server/models/User';

export default defineEventHandler(async (event) => {
const { email, password, name, role } = await readBody(event);

const existingUser = await User.findOne({ email });
if (existingUser) {
throw createError({
statusCode: 400,
statusMessage: 'User already exists.',
});
}

const hashedPassword = await bcrypt.hash(password, 10);

const user = new User({
email,
password: hashedPassword,
name,
role: role || 'customer',
});

await user.save();

const token = createJWT(user.email);

await setAuth(event, token);

return { success: true, user: { email: user.email, role: user.role } };
});
import bcrypt from 'bcryptjs';
import { createJWT } from '~/server/utils/jwt';
import User from '~/server/models/User';

export default defineEventHandler(async (event) => {
const { email, password, name, role } = await readBody(event);

const existingUser = await User.findOne({ email });
if (existingUser) {
throw createError({
statusCode: 400,
statusMessage: 'User already exists.',
});
}

const hashedPassword = await bcrypt.hash(password, 10);

const user = new User({
email,
password: hashedPassword,
name,
role: role || 'customer',
});

await user.save();

const token = createJWT(user.email);

await setAuth(event, token);

return { success: true, user: { email: user.email, role: user.role } };
});
15 replies
NNuxt
Created by Ahm@ on 9/12/2024 in #❓・help
Nuxt /app Pages Not Detecting API Route from /server Directory
app/pages/auth/register.vue file scripts:
async function onSubmit(data: any) {
isLoading.value = true;
try {
const { data: response, error } = await useFetch('/api/auth/register', {
method: 'POST',
body: { name: data.name, email: data.email, password: data.password },
});

if (error.value) {
userMessage.value = 'Registration failed. Please try again.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-x-circle', color: 'red' });
} else {
userMessage.value = 'Registration successful.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-check-circle', color: 'green' });
isSuccess.value = true;
router.push('/login');
}
} catch (err) {
console.error('Registration error:', err);
userMessage.value = 'Something went wrong. Please try again.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-x-circle', color: 'red' });
} finally {
isLoading.value = false;
}
}
async function onSubmit(data: any) {
isLoading.value = true;
try {
const { data: response, error } = await useFetch('/api/auth/register', {
method: 'POST',
body: { name: data.name, email: data.email, password: data.password },
});

if (error.value) {
userMessage.value = 'Registration failed. Please try again.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-x-circle', color: 'red' });
} else {
userMessage.value = 'Registration successful.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-check-circle', color: 'green' });
isSuccess.value = true;
router.push('/login');
}
} catch (err) {
console.error('Registration error:', err);
userMessage.value = 'Something went wrong. Please try again.';
toast.add({ title: userMessage.value, icon: 'i-heroicons-x-circle', color: 'red' });
} finally {
isLoading.value = false;
}
}
15 replies
NNuxt
Created by Ahm@ on 5/30/2024 in #❓・help
NuxtUI Carousel Problem
after clicking and dragging the mouse, I stop clicking the mouse but it keeps holding the gallery
2 replies