How do I pass invitation token with google auth to my backend?
import { CredentialResponse } from "../interfaces/google";
export const Login: React.FC = () => {
const { mutate: login } = useLogin<CredentialResponse>();
//http://localhost:3000/login?to=%2Flogin%2F754c8673492ef41ba151b4ed526e74dab4cf6151c5126d89c43c0bee8f765aab
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const token = queryParams.get("to")?.split("/login/")[1];
console.log(token);
const { loginWithRedirect } = useAuth0();
const GoogleButton = (): JSX.Element => {
const divRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (typeof window === "undefined" !window.google !divRef.current) {
return;
}
try {
window.google.accounts.id.initialize({
ux_mode: "popup",
client_id: "*-.apps.googleusercontent.com",
callback: async (res: CredentialResponse) => {
if (res.credential) {
res.token = token;
login(res);
}
},
});
window.google.accounts.id.renderButton(divRef.current, {
theme: "filled_blue",
size: "medium",
type: "standard",
});
} catch (error) {
console.log(error);
}
}, []); // you can also add your client id as dependency here
return <div ref={divRef} />;
};
return (
.....
<Box mt={4}>
<GoogleButton />
</Box>
);
};
The token what it should be passed to my backend.
and call this function: router.route('/login/:token').post(createUser);
I tested with postman and from backend part it was working well and created the user I expected
4 Replies
Hi @acidias. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. The provided code and information are not related to refine. However, if you have any questions about refine, I'd be happy to help. You can also check out the refine documentation here (https://refine.dev/docs) and blogs here (https://refine.dev/blog) for more information.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------Overview | refine
What is refine?
Blog | refine
A Docusaurus powered blog!
<@134090892167479296> kapa.ai is still learning and improving, please let us how it did by reacting below
equal-aqua•16mo ago
I have an invitations table in db, which being checked in my createUser function and if the token is valid it's takes the invitators ID and pass to the new user as it parentUserId.
So it's kinda become a subuser
I tried out my createUser function with postman and its worked correctly, however I don't know how to pass the token from frontend with refine.