calimero-auth-sdk
Advanced tools
Comparing version 0.5.8 to 0.5.9
@@ -27,1 +27,7 @@ import * as nearAPI from "near-api-js"; | ||
} | ||
export declare class CalimeroAuth { | ||
constructor(); | ||
isSignedIn(): boolean; | ||
signIn(config: any): void; | ||
signOut(): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CalimeroToken = exports.CalimeroTokenData = exports.WalletData = exports.MAX_CALIMERO_TOKEN_DURATION = void 0; | ||
exports.CalimeroAuth = exports.CalimeroToken = exports.CalimeroTokenData = exports.WalletData = exports.MAX_CALIMERO_TOKEN_DURATION = void 0; | ||
const js_sha256_1 = require("js-sha256"); | ||
@@ -73,11 +73,14 @@ const axios = require("axios"); | ||
class CalimeroAuth { | ||
static isSignedIn() { | ||
constructor() { } | ||
isSignedIn() { | ||
return localStorage.getItem("calimeroToken") !== null; | ||
} | ||
static signIn(config) { | ||
signIn(config) { | ||
if (!localStorage.getItem("calimeroSecret")) { | ||
console.log("No calimeroSecret, generating and redirecting to the wallet"); | ||
localStorage.setItem("calimeroSecret", randomstring.generate({ length: 128 })); | ||
localStorage.setItem("calimeroSecretHash", js_sha256_1.sha256.update(localStorage.getItem("calimeroSecret")).toString()); | ||
console.log("Redirect to the wallet"); | ||
const callbackUrl = encodeURIComponent(window.location.href); | ||
window.location.href = `${config.walletUrl}?message=${localStorage.getItem("calimeroSecretHash")}&callbackUrl=${callbackUrl}`; | ||
window.location.assign(`${config.walletUrl}?message=${localStorage.getItem("calimeroSecretHash")}&callbackUrl=${callbackUrl}`); | ||
} | ||
@@ -107,3 +110,3 @@ const search = window.location.search; | ||
} | ||
static signOut() { | ||
signOut() { | ||
localStorage.removeItem("calimeroToken"); | ||
@@ -114,2 +117,3 @@ localStorage.removeItem("calimeroSecret"); | ||
} | ||
exports.CalimeroAuth = CalimeroAuth; | ||
module.exports = { | ||
@@ -120,3 +124,3 @@ MAX_CALIMERO_TOKEN_DURATION: exports.MAX_CALIMERO_TOKEN_DURATION, | ||
CalimeroTokenData, | ||
CalimeroAuth, | ||
CalimeroAuth | ||
}; |
{ | ||
"name": "calimero-auth-sdk", | ||
"version": "0.5.8", | ||
"version": "0.5.9", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
43367
154