@0xchain/auth 1.1.0-beta.2 → 1.1.0-beta.20

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present 0xchain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ import request from "@0xchain/request";
2
+ import { default as default2 } from "./loginApi.js";
3
+ import { removeAllToken } from "@0xchain/token";
4
+ import { default as default3 } from "@0xchain/token";
5
+ function logout() {
6
+ removeAllToken();
7
+ const iframe = document.createElement("iframe");
8
+ iframe.src = `${process.env.NEXT_PUBLIC_AUTH_URL}/en/logout`;
9
+ window.addEventListener("message", (event) => {
10
+ if (event.data.type === "logout") {
11
+ iframe.remove();
12
+ if (window.location.pathname.includes("/user-center")) {
13
+ window.location.replace(process.env.NEXT_PUBLIC_BASE_URL || "/");
14
+ } else {
15
+ window.location.reload();
16
+ }
17
+ }
18
+ });
19
+ iframe.style.display = "none";
20
+ document.body.appendChild(iframe);
21
+ }
22
+ function fetchUserProfile() {
23
+ return request.get("/v2/users/profile").then((res) => {
24
+ if (res?.status?.code === 0) {
25
+ return res.data;
26
+ }
27
+ });
28
+ }
29
+ export {
30
+ default2 as LoginApi,
31
+ default3 as TokenManager,
32
+ fetchUserProfile,
33
+ logout
34
+ };
@@ -0,0 +1,32 @@
1
+ import request from "@0xchain/request";
2
+ import cookies from "js-cookie";
3
+ import { getToken, removeAllToken } from "@0xchain/token";
4
+ const loginApi = {
5
+ login: (data) => {
6
+ removeAllToken();
7
+ return request.post(`/api/login/email`, data, {
8
+ baseURL: process.env.NEXT_PUBLIC_AUTH_URL
9
+ });
10
+ },
11
+ getToken: () => {
12
+ cookies.set("Authorization", `Basic ${btoa("search-client:secret-search")}`);
13
+ window.location.href = `/oauth2/authorize?client_id=search-client&response_type=code&scope=openid%20profile&state=test-state-123&redirect_uri=${window.location.origin}/callback`;
14
+ },
15
+ refreshToken: () => {
16
+ return request.get(`/api/refresh/token`, {
17
+ params: {
18
+ grant_type: "refresh_token",
19
+ refresh_token: getToken("refresh_token")
20
+ },
21
+ baseURL: process.env.NEXT_PUBLIC_AUTH_URL
22
+ });
23
+ },
24
+ register: (data) => {
25
+ return request.post(`/api/register`, data, {
26
+ baseURL: process.env.NEXT_PUBLIC_AUTH_URL
27
+ });
28
+ }
29
+ };
30
+ export {
31
+ loginApi as default
32
+ };
package/package.json CHANGED
@@ -1,35 +1,42 @@
1
1
  {
2
2
  "name": "@0xchain/auth",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.20",
4
4
  "type": "module",
5
- "main": "./dist/index.mjs",
6
- "module": "./dist/index.mjs",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "default": "./dist/index.mjs"
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
14
  },
15
15
  "./loginApi": {
16
16
  "types": "./dist/loginApi/index.d.ts",
17
- "import": "./dist/loginApi.mjs",
18
- "default": "./dist/loginApi.mjs"
17
+ "import": "./dist/loginApi.js",
18
+ "default": "./dist/loginApi.js"
19
19
  }
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
23
  "!**/*.tsbuildinfo"
24
24
  ],
25
+ "peerDependencies": {
26
+ "js-cookie": "3.0.5"
27
+ },
25
28
  "devDependencies": {
26
29
  "@types/js-cookie": "3.0.6",
27
- "@types/next": "9.0.0"
30
+ "js-cookie": "3.0.5"
28
31
  },
29
32
  "dependencies": {
30
- "js-cookie": "3.0.5",
31
- "@0xchain/request": "1.1.0-beta.2",
32
- "@0xchain/token": "1.1.0-beta.2"
33
+ "@0xchain/request": "1.1.0-beta.20",
34
+ "@0xchain/token": "1.1.0-beta.20"
35
+ },
36
+ "nx": {
37
+ "tags": [
38
+ "type:util"
39
+ ]
33
40
  },
34
41
  "publishConfig": {
35
42
  "access": "public"
package/dist/index.mjs DELETED
@@ -1,24 +0,0 @@
1
- import t from "@0xchain/request";
2
- import { default as s } from "./loginApi.mjs";
3
- import { removeAllToken as n } from "@0xchain/token";
4
- import { default as u } from "@0xchain/token";
5
- function i() {
6
- n();
7
- const e = document.createElement("iframe");
8
- e.src = `${process.env.NEXT_PUBLIC_AUTH_URL}/en/logout`, window.addEventListener("message", (o) => {
9
- o.data.type === "logout" && (e.remove(), window.location.pathname.includes("/user-center") ? window.location.replace(process.env.NEXT_PUBLIC_BASE_URL || "/") : window.location.reload());
10
- }), e.style.display = "none", document.body.appendChild(e);
11
- }
12
- function l() {
13
- return t.get("/v2/users/profile").then((e) => {
14
- var o;
15
- if (((o = e == null ? void 0 : e.status) == null ? void 0 : o.code) === 0)
16
- return e.data;
17
- });
18
- }
19
- export {
20
- s as LoginApi,
21
- u as TokenManager,
22
- l as fetchUserProfile,
23
- i as logout
24
- };
package/dist/loginApi.mjs DELETED
@@ -1,24 +0,0 @@
1
- import r from "@0xchain/request";
2
- import o from "js-cookie";
3
- import { getToken as t, removeAllToken as s } from "@0xchain/token";
4
- const c = {
5
- login: (e) => (s(), r.post("/api/login/email", e, {
6
- baseURL: process.env.NEXT_PUBLIC_AUTH_URL
7
- })),
8
- getToken: () => {
9
- o.set("Authorization", `Basic ${btoa("search-client:secret-search")}`), window.location.href = `/oauth2/authorize?client_id=search-client&response_type=code&scope=openid%20profile&state=test-state-123&redirect_uri=${window.location.origin}/callback`;
10
- },
11
- refreshToken: () => r.get("/api/refresh/token", {
12
- params: {
13
- grant_type: "refresh_token",
14
- refresh_token: t("refresh_token")
15
- },
16
- baseURL: process.env.NEXT_PUBLIC_AUTH_URL
17
- }),
18
- register: (e) => r.post("/api/register", e, {
19
- baseURL: process.env.NEXT_PUBLIC_AUTH_URL
20
- })
21
- };
22
- export {
23
- c as default
24
- };