mirror of
https://github.com/TheRealOwenRees/chess-scribe-website.git
synced 2026-07-23 01:46:57 +00:00
check callback from lichess server
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { useServerFn } from "@tanstack/react-start";
|
||||
import { useState } from "react";
|
||||
import { getToken, login } from "#/server/lichess.ts";
|
||||
|
||||
export const useLichess = () => {
|
||||
const [lichessUser, setLichessUser] = useState();
|
||||
|
||||
const triggerLogin = useServerFn(login);
|
||||
const trigggerGetToken = useServerFn(getToken);
|
||||
|
||||
console.log("Lichess User:", lichessUser);
|
||||
|
||||
const lichessTokenVerification = async ({ code }) => {
|
||||
await trigggerGetToken();
|
||||
};
|
||||
|
||||
const lichessLogin = async () => {
|
||||
// TODO add try/catch with toast
|
||||
await triggerLogin();
|
||||
};
|
||||
|
||||
const lichessLogout = () => {
|
||||
console.log("Lichess Logout");
|
||||
};
|
||||
|
||||
return {
|
||||
lichessLogin,
|
||||
lichessLogout,
|
||||
lichessTokenVerification,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useEffect } from "react";
|
||||
import { useLichess } from "#/hooks/useLichess.ts";
|
||||
|
||||
interface IProps {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export const useLichessCallback = ({ code }: IProps) => {
|
||||
const { lichessTokenVerification } = useLichess();
|
||||
|
||||
useEffect(() => {
|
||||
if (!code) return;
|
||||
|
||||
const response = lichessTokenVerification({ code });
|
||||
console.log("Response:", response);
|
||||
}, [code, lichessTokenVerification]);
|
||||
};
|
||||
Reference in New Issue
Block a user