From 2118a55ab62200e87f210739483d843aa64b454f Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Tue, 14 Jan 2025 09:07:00 +0100 Subject: [PATCH] Updates --- client/auth/post-login.ts | 20 ++++++++++++++++++++ client/index.ts | 11 +++-------- dist/client/auth/post-login.d.ts | 9 +++++++++ dist/client/auth/post-login.js | 24 ++++++++++++++++++++++++ dist/client/index.d.ts | 2 ++ dist/client/index.js | 8 ++------ dist/index.d.ts | 1 + package.json | 2 +- 8 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 client/auth/post-login.ts create mode 100644 dist/client/auth/post-login.d.ts create mode 100644 dist/client/auth/post-login.js diff --git a/client/auth/post-login.ts b/client/auth/post-login.ts new file mode 100644 index 0000000..1f61e32 --- /dev/null +++ b/client/auth/post-login.ts @@ -0,0 +1,20 @@ +import { APILoginFunctionReturn } from "../../package-shared/types"; + +/** + * Client Setup After Login + * =============================================================================== + * @description This function sets local storage variables like `csrf` after a user + * is logged in. Use this in conjunction with the `datasquirel.user.loginUser` + * function + */ +export default function postLogin(res: APILoginFunctionReturn): boolean { + try { + if (!res.payload) return false; + if (!res.payload.csrf_k) return false; + localStorage.setItem("csrf", res.payload.csrf_k); + localStorage.setItem("user", JSON.stringify(res.payload)); + return true; + } catch (error) { + return false; + } +} diff --git a/client/index.ts b/client/index.ts index 7320ef9..9aca2ca 100644 --- a/client/index.ts +++ b/client/index.ts @@ -11,14 +11,8 @@ import serializeCookies from "../package-shared/utils/serialize-cookies"; import EJSON from "../package-shared/utils/ejson"; import numberfy from "../package-shared/utils/numberfy"; import slugify from "../package-shared/utils/slugify"; +import postLogin from "./auth/post-login"; -//////////////////////////////////////// -//////////////////////////////////////// -//////////////////////////////////////// - -/** - * Media Functions Object - */ const media = { imageInputToBase64: imageInputToBase64, imageInputFileToBase64: imageInputFileToBase64, @@ -35,7 +29,8 @@ const auth = { github: { getAccessToken: getGithubAccessToken, }, - logout: logout, + logout, + postLogin, }; const utils = { diff --git a/dist/client/auth/post-login.d.ts b/dist/client/auth/post-login.d.ts new file mode 100644 index 0000000..812a233 --- /dev/null +++ b/dist/client/auth/post-login.d.ts @@ -0,0 +1,9 @@ +import { APILoginFunctionReturn } from "../../package-shared/types"; +/** + * Client Setup After Login + * =============================================================================== + * @description This function sets local storage variables like `csrf` after a user + * is logged in. Use this in conjunction with the `datasquirel.user.loginUser` + * function + */ +export default function postLogin(res: APILoginFunctionReturn): boolean; diff --git a/dist/client/auth/post-login.js b/dist/client/auth/post-login.js new file mode 100644 index 0000000..52fe9ae --- /dev/null +++ b/dist/client/auth/post-login.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = postLogin; +/** + * Client Setup After Login + * =============================================================================== + * @description This function sets local storage variables like `csrf` after a user + * is logged in. Use this in conjunction with the `datasquirel.user.loginUser` + * function + */ +function postLogin(res) { + try { + if (!res.payload) + return false; + if (!res.payload.csrf_k) + return false; + localStorage.setItem("csrf", res.payload.csrf_k); + localStorage.setItem("user", JSON.stringify(res.payload)); + return true; + } + catch (error) { + return false; + } +} diff --git a/dist/client/index.d.ts b/dist/client/index.d.ts index 3ef3666..b9a46eb 100644 --- a/dist/client/index.d.ts +++ b/dist/client/index.d.ts @@ -9,6 +9,7 @@ import serializeQuery from "../package-shared/utils/serialize-query"; import serializeCookies from "../package-shared/utils/serialize-cookies"; import numberfy from "../package-shared/utils/numberfy"; import slugify from "../package-shared/utils/slugify"; +import postLogin from "./auth/post-login"; /** * Main Export */ @@ -26,6 +27,7 @@ declare const datasquirelClient: { getAccessToken: typeof getGithubAccessToken; }; logout: typeof logout; + postLogin: typeof postLogin; }; fetch: { fetchApi: typeof fetchApi; diff --git a/dist/client/index.js b/dist/client/index.js index a29d5fb..1c920c9 100644 --- a/dist/client/index.js +++ b/dist/client/index.js @@ -16,12 +16,7 @@ const serialize_cookies_1 = __importDefault(require("../package-shared/utils/ser const ejson_1 = __importDefault(require("../package-shared/utils/ejson")); const numberfy_1 = __importDefault(require("../package-shared/utils/numberfy")); const slugify_1 = __importDefault(require("../package-shared/utils/slugify")); -//////////////////////////////////////// -//////////////////////////////////////// -//////////////////////////////////////// -/** - * Media Functions Object - */ +const post_login_1 = __importDefault(require("./auth/post-login")); const media = { imageInputToBase64: imageInputToBase64_1.default, imageInputFileToBase64: imageInputFileToBase64_1.default, @@ -38,6 +33,7 @@ const auth = { getAccessToken: getAccessToken_2.default, }, logout: logout_1.default, + postLogin: post_login_1.default, }; const utils = { serializeQuery: serialize_query_1.default, diff --git a/dist/index.d.ts b/dist/index.d.ts index b44b1b1..136eba0 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -76,6 +76,7 @@ declare const datasquirel: { getAccessToken: typeof import("./client/auth/github/getAccessToken").default; }; logout: typeof import("./client/auth/logout").default; + postLogin: typeof import("./client/auth/post-login").default; }; fetch: { fetchApi: typeof import("./client/fetch").default; diff --git a/package.json b/package.json index 8987c98..151330b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "3.4.6", + "version": "3.4.7", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": {