datasquirel/client/auth/github/getAccessToken.ts

25 lines
755 B
TypeScript
Raw Normal View History

2025-01-10 19:10:28 +00:00
type Param = {
clientId: string;
redirectUrl: string;
setLoading?: (arg0: boolean) => void;
scopes?: string[];
};
/**
* Login with Github Function
* ===============================================================================
* @description This function uses github api to login a user with datasquirel
*/
export default function getAccessToken({
clientId,
redirectUrl,
setLoading,
scopes,
}: Param): void {
if (setLoading) setLoading(true);
const scopeString = scopes ? scopes.join("%20") : "read:user";
const fetchUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&scope=${scopeString}&redirect_uri=${redirectUrl}`;
window.location.assign(fetchUrl);
}