Updates
This commit is contained in:
+1
-4
@@ -1,12 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = getAccessToken;
|
||||
/**
|
||||
* Login with Github Function
|
||||
* ===============================================================================
|
||||
* @description This function uses github api to login a user with datasquirel
|
||||
*/
|
||||
function getAccessToken({ clientId, redirectUrl, setLoading, scopes, }) {
|
||||
export default function getAccessToken({ clientId, redirectUrl, setLoading, scopes, }) {
|
||||
if (setLoading)
|
||||
setLoading(true);
|
||||
const scopeString = scopes ? scopes.join("%20") : "read:user";
|
||||
|
||||
+16
-31
@@ -1,44 +1,29 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = getAccessToken;
|
||||
exports.googleLogin = googleLogin;
|
||||
let interval;
|
||||
/**
|
||||
* Login with Google Function
|
||||
* ===============================================================================
|
||||
* @description This function uses google identity api to login a user with datasquirel
|
||||
*/
|
||||
function getAccessToken(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
(_a = params.setLoading) === null || _a === void 0 ? void 0 : _a.call(params, true);
|
||||
const response = (yield new Promise((resolve, reject) => {
|
||||
interval = setInterval(() => {
|
||||
// @ts-ignore
|
||||
let google = window.google;
|
||||
if (google) {
|
||||
window.clearInterval(interval);
|
||||
resolve(googleLogin(Object.assign(Object.assign({}, params), { google })));
|
||||
}
|
||||
}, 500);
|
||||
}));
|
||||
(_b = params.setLoading) === null || _b === void 0 ? void 0 : _b.call(params, false);
|
||||
return response;
|
||||
});
|
||||
export default async function getAccessToken(params) {
|
||||
var _a, _b;
|
||||
(_a = params.setLoading) === null || _a === void 0 ? void 0 : _a.call(params, true);
|
||||
const response = (await new Promise((resolve, reject) => {
|
||||
interval = setInterval(() => {
|
||||
// @ts-ignore
|
||||
let google = window.google;
|
||||
if (google) {
|
||||
window.clearInterval(interval);
|
||||
resolve(googleLogin(Object.assign(Object.assign({}, params), { google })));
|
||||
}
|
||||
}, 500);
|
||||
}));
|
||||
(_b = params.setLoading) === null || _b === void 0 ? void 0 : _b.call(params, false);
|
||||
return response;
|
||||
}
|
||||
/**
|
||||
* # Google Login Function
|
||||
*/
|
||||
function googleLogin({ google, clientId, setLoading, triggerPrompt, }) {
|
||||
export function googleLogin({ google, clientId, setLoading, triggerPrompt, }) {
|
||||
setTimeout(() => {
|
||||
setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
|
||||
}, 3000);
|
||||
|
||||
Vendored
+72
-89
@@ -1,103 +1,86 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = logout;
|
||||
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
|
||||
const parseClientCookies_1 = __importDefault(require("../utils/parseClientCookies"));
|
||||
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
|
||||
import parseClientCookies from "../utils/parseClientCookies";
|
||||
/**
|
||||
* Login with Google Function
|
||||
* ===============================================================================
|
||||
* @description This function uses google identity api to login a user with datasquirel
|
||||
*/
|
||||
function logout(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
export default async function logout(params) {
|
||||
try {
|
||||
const localUser = localStorage.getItem("user");
|
||||
let targetUser;
|
||||
try {
|
||||
const localUser = localStorage.getItem("user");
|
||||
let targetUser;
|
||||
try {
|
||||
targetUser = JSON.parse(localUser || "");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (!targetUser) {
|
||||
return false;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const cookies = (0, parseClientCookies_1.default)();
|
||||
const socialId = (cookies === null || cookies === void 0 ? void 0 : cookies.datasquirel_social_id) &&
|
||||
typeof cookies.datasquirel_social_id == "string" &&
|
||||
!cookies.datasquirel_social_id.match(/^null$/i)
|
||||
? cookies.datasquirel_social_id
|
||||
: null;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
localStorage.setItem("user", "{}");
|
||||
localStorage.removeItem((0, get_csrf_header_name_1.default)());
|
||||
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const response = yield new Promise((resolve, reject) => {
|
||||
if (socialId && !(socialId === null || socialId === void 0 ? void 0 : socialId.match(/^null$/i))) {
|
||||
const googleClientId = params === null || params === void 0 ? void 0 : params.googleClientId;
|
||||
if (googleClientId) {
|
||||
const googleScript = document.createElement("script");
|
||||
googleScript.src = "https://accounts.google.com/gsi/client";
|
||||
googleScript.className = "social-script-tag";
|
||||
document.body.appendChild(googleScript);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
googleScript.onload = function (e) {
|
||||
// @ts-ignore
|
||||
const google = window.google;
|
||||
if (google) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
google.accounts.id.initialize({
|
||||
client_id: googleClientId,
|
||||
});
|
||||
google.accounts.id.revoke(socialId, (done) => {
|
||||
console.log(done.error);
|
||||
resolve(true);
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
resolve(true);
|
||||
}
|
||||
targetUser = JSON.parse(localUser || "");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (!targetUser) {
|
||||
return false;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const cookies = parseClientCookies();
|
||||
const socialId = (cookies === null || cookies === void 0 ? void 0 : cookies.datasquirel_social_id) &&
|
||||
typeof cookies.datasquirel_social_id == "string" &&
|
||||
!cookies.datasquirel_social_id.match(/^null$/i)
|
||||
? cookies.datasquirel_social_id
|
||||
: null;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
localStorage.setItem("user", "{}");
|
||||
localStorage.removeItem(getCsrfHeaderName());
|
||||
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
if (socialId && !(socialId === null || socialId === void 0 ? void 0 : socialId.match(/^null$/i))) {
|
||||
const googleClientId = params === null || params === void 0 ? void 0 : params.googleClientId;
|
||||
if (googleClientId) {
|
||||
const googleScript = document.createElement("script");
|
||||
googleScript.src = "https://accounts.google.com/gsi/client";
|
||||
googleScript.className = "social-script-tag";
|
||||
document.body.appendChild(googleScript);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
googleScript.onload = function (e) {
|
||||
// @ts-ignore
|
||||
const google = window.google;
|
||||
if (google) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
google.accounts.id.initialize({
|
||||
client_id: googleClientId,
|
||||
});
|
||||
google.accounts.id.revoke(socialId, (done) => {
|
||||
console.log(done.error);
|
||||
resolve(true);
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
return response;
|
||||
}
|
||||
catch (error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
return response;
|
||||
}
|
||||
catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-9
@@ -1,10 +1,4 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = postLogin;
|
||||
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
|
||||
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
|
||||
/**
|
||||
* Client Setup After Login
|
||||
* ===============================================================================
|
||||
@@ -12,13 +6,13 @@ const get_csrf_header_name_1 = __importDefault(require("../../package-shared/act
|
||||
* is logged in. Use this in conjunction with the `datasquirel.user.loginUser`
|
||||
* function
|
||||
*/
|
||||
function postLogin(res) {
|
||||
export default function postLogin(res) {
|
||||
try {
|
||||
if (!res.payload)
|
||||
return false;
|
||||
if (!res.payload.csrf_k)
|
||||
return false;
|
||||
localStorage.setItem((0, get_csrf_header_name_1.default)(), res.payload.csrf_k);
|
||||
localStorage.setItem(getCsrfHeaderName(), res.payload.csrf_k);
|
||||
localStorage.setItem("user", JSON.stringify(res.payload));
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user