weightxreps-oauth
Version:
Module to let your javascript app get user's credentials of [weightxreps.net](https://weightxreps.net/). It only focus on obtaining a valid access token, you are then responsible of adding it to your request's headers when connecting to the GraphQL endpoi
34 lines (33 loc) • 1.33 kB
TypeScript
import type { Options } from "./OauthClient";
import { WxrUser } from "./OauthClient";
type Maybe<T> = T | null;
type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
[SubKey in K]?: Maybe<T[SubKey]>;
};
type HookApi = {
/**
* Triggers the login ui flow. Either open a popup window or redirect the page, depending on your settings.
*/
login: () => Promise<WxrUser>;
/**
* Will contian the basic data of the weightxreps user that granted us the access.
*/
user?: WxrUser;
/**
* Get headers to be used in `fetch` calls or similar to the weightxreps api.
* @param loginIfNeeded Will trigger a login same as calling `.login` if needed.
* @returns an object containing the headers you should add to any request you do to the graphql api
*/
getAuthHeaders?: (loginIfNeeded?: boolean) => Promise<Object>;
/**
* In case of error, this will contain the text or code...
*/
error?: string;
/**
* Logout the user on this client. It just removes the token from the localstorage and will update the user and token to undefined.
*/
logout: () => void;
loading?: boolean;
};
export declare const useWeightxrepsOAuth: (client_id: string, options: MakeOptional<Options, "fetch" | "store" | "asPopup" | "redirectUri">) => HookApi;
export {};