dead-brownD
Refine2y ago
5 replies
dead-brown

AuthProvider with Spring Boot

Hello, I've just recently started playing around with React in general and Refine. I'm trying to connect the starter app's login page with a Spring Boot backend to initially authenticate and I'm having some trouble. I was able to get my data provider seemingly setup correctly (just using the simple-rest provider that comes with Refine out of box) and was able to fetch some data without issue. But the login method on my AuthProvider keeps returning an error and I'm not sure why. On the Spring Boot side of things, I added some debug output in and can see that I'm getting a server hit, but there's no content being passed in the body of the request (which I imagine makes Spring boot discard it as a bad request since it can't match to the exposed method which is expecting an email address). My AuthProvider is attached below - any insight into why its not passing anything?

export const authProvider: AuthBindings = {
    login: async ({ email }) => {
        try {
            const { data } = await restProvider.custom({
                url: API_BASE_URL,
                method: "post",
                headers: {},
                query: {
                    email: email
                }
            });

            localStorage.setItem("access_token", data.login.accessToken);

            return {
                success: true,
                redirectTo: "/",
            };
        } catch (e) {
            const error = e as Error;

            return {
                success: false,
                error: {
                    message: "message" in error ? error.message : "Login failed",
                    name: "name" in error ? error.name : "Invalid email or password",
                },
            };
        }
    },
Was this page helpful?