polyfire-js
Advanced tools
Comparing version 0.2.41 to 0.2.42
@@ -54,5 +54,5 @@ import { ClientOptions } from "./clientOpts"; | ||
endpoint: string; | ||
}): Promise<boolean>; | ||
}, autoLogin?: boolean): Promise<boolean>; | ||
export type AuthClient = { | ||
init: () => Promise<boolean>; | ||
init: (autoLogin?: boolean) => Promise<boolean>; | ||
login: (input: LoginFunctionInput) => Promise<void>; | ||
@@ -59,0 +59,0 @@ logout: () => Promise<void>; |
@@ -279,3 +279,4 @@ "use strict"; | ||
exports.logout = logout; | ||
function init(co, projectOptions) { | ||
function init(co, projectOptions, autoLogin) { | ||
if (autoLogin === void 0) { autoLogin = true; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -287,2 +288,5 @@ var e_3, session; | ||
_a.trys.push([0, 2, , 4]); | ||
if (!autoLogin) { | ||
throw new error_1.PolyfireError("Auto login disabled"); | ||
} | ||
return [4 /*yield*/, signInAnon(undefined, co, projectOptions)]; | ||
@@ -318,3 +322,3 @@ case 1: | ||
return { | ||
init: function () { return init(co, projectOptions); }, | ||
init: function (autoLogin) { return init(co, projectOptions, autoLogin); }, | ||
login: function (input) { return login(input, projectOptions, co); }, | ||
@@ -321,0 +325,0 @@ logout: function () { return logout(co); }, |
import { ReactNode, JSX } from "react"; | ||
import { Client } from "../client"; | ||
type AuthStatus = "loading" | "authenticated" | "unauthenticated"; | ||
export declare function PolyfireProvider({ children, project, endpoint, }: { | ||
export declare function PolyfireProvider({ children, project, endpoint, autoLogin, }: { | ||
children: ReactNode; | ||
project: string; | ||
endpoint?: string; | ||
autoLogin?: boolean; | ||
}): JSX.Element; | ||
@@ -9,0 +10,0 @@ export default function usePolyfire(): Omit<Client, "auth"> & { |
@@ -83,7 +83,7 @@ "use strict"; | ||
function PolyfireProvider(_a) { | ||
var children = _a.children, project = _a.project, _b = _a.endpoint, endpoint = _b === void 0 ? "https://api.polyfire.com" : _b; | ||
var children = _a.children, project = _a.project, _b = _a.endpoint, endpoint = _b === void 0 ? "https://api.polyfire.com" : _b, autoLogin = _a.autoLogin; | ||
var _c = (0, react_1.useState)("loading"), status = _c[0], setStatus = _c[1]; | ||
var polyfire = (0, react_1.useState)(function () { return (0, client_1.default)({ project: project, endpoint: endpoint }); })[0]; | ||
(0, react_1.useEffect)(function () { | ||
polyfire.auth.init().then(function (isAuthenticated) { | ||
polyfire.auth.init(autoLogin).then(function (isAuthenticated) { | ||
setStatus(isAuthenticated ? "authenticated" : "unauthenticated"); | ||
@@ -90,0 +90,0 @@ }); |
{ | ||
"name": "polyfire-js", | ||
"version": "0.2.41", | ||
"version": "0.2.42", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
280350
5689