@uniquei/react 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +74 -0
- package/package.json +16 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AnywhereAuth: () => AnywhereAuth
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var CLIENT_URL = "https://act-sys.vercel.app";
|
|
27
|
+
var DEVS_URL = "https://actx.vercel.app";
|
|
28
|
+
var AnywhereAuthClass = class {
|
|
29
|
+
get token() {
|
|
30
|
+
if (typeof window === "undefined") return null;
|
|
31
|
+
return localStorage.getItem("anywhere_sso_token");
|
|
32
|
+
}
|
|
33
|
+
set token(value) {
|
|
34
|
+
if (typeof window === "undefined") return;
|
|
35
|
+
if (value) localStorage.setItem("anywhere_sso_token", value);
|
|
36
|
+
else localStorage.removeItem("anywhere_sso_token");
|
|
37
|
+
}
|
|
38
|
+
handleTokenFromUrl() {
|
|
39
|
+
if (typeof window === "undefined") return;
|
|
40
|
+
const params = new URLSearchParams(window.location.search);
|
|
41
|
+
const token = params.get("token");
|
|
42
|
+
if (token) {
|
|
43
|
+
this.token = token;
|
|
44
|
+
window.history.replaceState({}, document.title, window.location.pathname);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
init() {
|
|
48
|
+
this.handleTokenFromUrl();
|
|
49
|
+
}
|
|
50
|
+
async getUser() {
|
|
51
|
+
if (!this.token) return null;
|
|
52
|
+
const res = await fetch(`${DEVS_URL}/api/users/fetch`, {
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `Bearer ${this.token}`
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!res.ok) return null;
|
|
58
|
+
return res.json();
|
|
59
|
+
}
|
|
60
|
+
login() {
|
|
61
|
+
const redirect = encodeURIComponent(
|
|
62
|
+
`${window.location.origin}/`
|
|
63
|
+
);
|
|
64
|
+
window.location.href = `${CLIENT_URL}/api/sso?redirect=${redirect}`;
|
|
65
|
+
}
|
|
66
|
+
logout() {
|
|
67
|
+
this.token = null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var AnywhereAuth = new AnywhereAuthClass();
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
AnywhereAuth
|
|
74
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniquei/react",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"tsup": "^8.5.1",
|
|
14
|
+
"typescript": "^5.9.3"
|
|
15
|
+
}
|
|
16
|
+
}
|