NextJS - login With Password Answered
Has anyone had problems using server actions in nextJS?
Calling the login server action "loginWithPassword({email, password})" returns "Cannot read properties of undefined (reading 'tokens')" as a 200 response.
Unfortunately as this is on behalf of a client it is in a private repo 😞.
To add further info, the users to log in are "test users". We are testing memberstack before hopefully upgrading our account and using it for our project.
In a server component I export the login function as follows:export const login = async (creds: any) => {
try {
const user = await memberstackServer.loginWithPassword({
email: creds.email,
password: creds.password,
});
return user;
} catch (error: any) {
return error.message;
}
};
Please note the "memberstackServer" part is how I initialized and imported memberstack in a separate component containing const memberstackServer = new MemberStack(apiKey);
I can see that the initialisation itself worked because other server actions such as updating password are working fine.
I can also see the credentials are being received from the client component, as console.logging them in the server shows they are correctly received.
Comments
4 comments
Apparently there's a bug with the library.
Have you tried using the DOM library but in a client component? You could use that login method in the meantime.
Thank you Raquel Lopez. It is working fine with the react and admin package, but the server actions are closer to the solution needed for our project.
I shall contact the report bugs channel
I see.
Well, the NextJS package is a wrapper of the React package that is in time a wrapper of the DOM package, so at the end of the day the methods found in those packages are the same. The admin package is the real "server side" package that even requires the secret key, instead of the public key. I think you should be able to create your own login module using the DOM package (even as a server action) 🙂
Got it, thanks for all your help.
Please sign in to leave a comment.