polyfire-js
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -12,9 +12,13 @@ import { ClientOptions } from "./clientOpts"; | ||
}; | ||
type LoginWithRawPolyfireTokenInput = { | ||
token: string; | ||
provider: "raw-polyfire"; | ||
}; | ||
type LoginAnonymousInput = { | ||
provider: "anonymous"; | ||
email: string; | ||
email?: string; | ||
}; | ||
type LoginFunctionInput = SimpleProvider | { | ||
provider: SimpleProvider; | ||
} | LoginWithFirebaseInput | LoginWithCustomInput | LoginAnonymousInput; | ||
} | LoginWithFirebaseInput | LoginWithCustomInput | LoginAnonymousInput | LoginWithRawPolyfireTokenInput; | ||
export declare function getSession(projectId: string, { endpoint }: { | ||
@@ -35,6 +39,10 @@ endpoint: string; | ||
}): Promise<void>; | ||
export declare function signInAnon(email: string, co: MutablePromise<Partial<ClientOptions>>, { project, endpoint }: { | ||
export declare function signInAnon(email: string | undefined, co: MutablePromise<Partial<ClientOptions>>, { project, endpoint }: { | ||
project: string; | ||
endpoint: string; | ||
}): Promise<void>; | ||
export declare function signInWithPolyfireToken(token: string, co: MutablePromise<Partial<ClientOptions>>, { endpoint }: { | ||
project: string; | ||
endpoint: string; | ||
}): Promise<void>; | ||
export declare function login(input: LoginFunctionInput, projectOptions: { | ||
@@ -41,0 +49,0 @@ project: string; |
29
auth.js
@@ -73,3 +73,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.init = exports.logout = exports.login = exports.signInAnon = exports.signInWithOAuthToken = exports.oAuthRedirect = exports.getSession = void 0; | ||
exports.init = exports.logout = exports.login = exports.signInWithPolyfireToken = exports.signInAnon = exports.signInWithOAuthToken = exports.oAuthRedirect = exports.getSession = void 0; | ||
var axios_1 = __importStar(require("axios")); | ||
@@ -187,7 +187,10 @@ var buffer_1 = require("buffer"); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var emailBase64, data, e_2; | ||
var basic, data, e_2; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
emailBase64 = buffer_1.Buffer.from(email).toString("base64"); | ||
basic = "auto"; | ||
if (email) { | ||
basic = buffer_1.Buffer.from(email).toString("base64"); | ||
} | ||
_c.label = 1; | ||
@@ -197,3 +200,3 @@ case 1: | ||
return [4 /*yield*/, axios_1.default.get("".concat(endpoint, "/project/").concat(project, "/auth/anonymous"), { | ||
headers: { Authorization: "Bearer ".concat(emailBase64) }, | ||
headers: { Authorization: "Basic ".concat(basic) }, | ||
})]; | ||
@@ -216,2 +219,12 @@ case 2: | ||
exports.signInAnon = signInAnon; | ||
function signInWithPolyfireToken(token, co, _a) { | ||
var endpoint = _a.endpoint; | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
co.set({ token: token, endpoint: endpoint }); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
} | ||
exports.signInWithPolyfireToken = signInWithPolyfireToken; | ||
function login(input, projectOptions, co) { | ||
@@ -238,6 +251,12 @@ return __awaiter(this, void 0, void 0, function () { | ||
case 5: | ||
if (!(typeof input === "object" && input.provider === "raw-polyfire")) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, signInWithPolyfireToken(input.token, co, projectOptions)]; | ||
case 6: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
case 7: | ||
provider = typeof input === "string" ? input : input.provider; | ||
oAuthRedirect(__assign({ provider: provider }, projectOptions)); | ||
return [4 /*yield*/, new Promise(function (_res, _rej) { })]; | ||
case 6: | ||
case 8: | ||
_a.sent(); | ||
@@ -244,0 +263,0 @@ return [2 /*return*/]; |
{ | ||
"name": "polyfire-js", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
2474376
4030