#Catch error on front end after fetch
8 messages · Page 1 of 1 (latest)
@sharp gulch sorry I keep bugging you but you seem to have a good idea of these questions
Np! What does the api/auth/callback/credentials code look like? Like how is that new Error() handled there?
`import type { Provider } from '@auth/core/providers'
import CredentialsProvider from '@auth/core/providers/credentials'
import { serverAuth$ } from '@builder.io/qwik-auth'
import { PrismaClient } from '@prisma/client'
import { compare } from 'bcrypt'
export const { useAuthSignin, useAuthSignout, useAuthSession, onRequest } = serverAuth$(
() => {
return ({
secret: import.meta.env.VITE_AUTH_SECRET,
trustHost: true,
providers: [
CredentialsProvider({
name: 'Login',
// @ts-ignore
authorize: async (credentials: any) => {
const prisma = new PrismaClient()
const email = credentials.email.trim()
const password = credentials.password.trim()
if (email === '' || password === '') {
throw new Error('Missing email or password')
}
const user = await prisma.user.findUnique({
where: {
email,
},
})
if (!user || !(await compare(password, user.password))) {
throw new Error('Invalid email or password')
} else {
return user
}
},
credentials: {
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' },
},
}),
] as Provider[],
pages: {
signIn: '/login',
},
session: {
strategy: 'jwt',
},
})
})`
Okay interesting. You're passing this anonymous function in so I'm not entirely sure where you should catch it to throw it back out to the frontend, since the auth framework here is eating that. I'm afraid I'm just not familiar with qwik-auth yet 😭 All the auth stuff I've done in Qwik so far has been done manually
Okay thank you for taking a look!