#Catch error on front end after fetch

8 messages · Page 1 of 1 (latest)

wind cliff
#

If anyone is wondering, when I remove the catch the error still shows up in my terminal

wind cliff
#

@sharp gulch sorry I keep bugging you but you seem to have a good idea of these questions

sharp gulch
#

Np! What does the api/auth/callback/credentials code look like? Like how is that new Error() handled there?

wind cliff
#

`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',
        },
    })
})`
sharp gulch
#

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

wind cliff
#

Okay thank you for taking a look!

wind cliff
#

I think I will create my own authentication

#

Does anyone know using json auth instead of server authentication prevents server-side rendering protected pages? (Probably a dumb question)