Question:
getting oauth flow timed out and promise not resolving when calling getMemberTokenForDirectLogin function of wix sdk
Product:
wix headless ecom along with next js
What are you trying to achieve:
i have a custom login page which uses wix headless wixclient.auth.login function to login user and when user logs in i get a response with login status and session token if successfull. now we need to extract this token for further processing by using getMemberTokenForDirectLogin but that is not resolving. it is a promise that never resolves and eventually gets timed out rest all is working fine and my process get stuck at this point
What have you already tried:
i tried not awaiting the function getMemberTokenForDirectLogin then it returned me a promise but if i await it it never gets resolved
Additional information:
“use client”;
import { FormField } from “…/…/types”;
import ReusableForm from “./ReusableForm”;
import Link from “next/link”;
import { login } from “@/app/api/auth”;
import { useWixClient } from “@/hooks/useWixClient”;
import { useRouter } from “next/navigation”;
import { LoginState } from “@wix/sdk”;
import Cookies from “js-cookie”;
import { loginSchema } from “@/lib/validations/auth”;
import { useToast } from “@/hooks/use-toast”;
const formFields: FormField = [
{
label: “Email ID”,
name: “email”,
type: “email”,
placeholder: “johndoe@gmail.com”,
},
{
label: “Password”,
name: “password”,
type: “password”,
placeholder: “johndoe@gmail.com”,
},
];
const LoginForm = () => {
const wixClient = useWixClient();
const router = useRouter();
const { toast } = useToast();
const handleSubmit = async (values: { [key: string]: string }) => {
const validatedFields = loginSchema.safeParse(values);
if (!validatedFields.success) {
throw validatedFields.error;
}
try {
console.log("logging in");
const res = await wixClient.auth.login({
email: validatedFields.data.email,
password: validatedFields.data.password,
});
if (res.loginState === LoginState.FAILURE) {
throw new Error("Invalid email or password");
}
if (res.loginState === LoginState.SUCCESS) {
console.log("log in success");
const sessionToken = res.data.sessionToken;
const tokens = await wixClient.auth.getMemberTokensForDirectLogin(
sessionToken
);
console.log("tokens", tokens);
// wixClient.auth.setTokens(tokens);
// Cookies.set("wix_auth", JSON.stringify(tokens), { expires: 7 });
// Add success toast
toast({
title: "Success!",
description: "You've successfully logged in. Welcome back!",
variant: "default",
});
router.push("/");
}
} catch (error) {
throw error;
}
};
return (
{LOGIN YOUR ACCOUNT
}
Forgot Password ?
);
};
export default LoginForm;
this is my code block