@liveartx/authentication 1.0.1 → 1.0.2

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.
@@ -0,0 +1 @@
1
+ export declare function getAuthToken(cookieName?: string): string | null;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuthToken = void 0;
4
+ const cookieService_1 = require("../services/cookieService");
5
+ function getAuthToken(cookieName = 'auth_token') {
6
+ return cookieService_1.cookieService.get(cookieName);
7
+ }
8
+ exports.getAuthToken = getAuthToken;
@@ -1,4 +1,3 @@
1
- import { AuthApiClient } from '~/api/authApiClient';
2
1
  interface AuthTokenData {
3
2
  accessToken: string;
4
3
  tokenType: string;
@@ -19,7 +18,7 @@ interface VerifyCodeResult {
19
18
  tokenData: AuthTokenData | null;
20
19
  error: string | null;
21
20
  }
22
- declare function sendVerificationCode(email: string, authClient: AuthApiClient): Promise<SendCodeResult>;
23
- declare function verifyCodeAndSaveToken(email: string, code: string, authClient: AuthApiClient, cookieName?: string): Promise<VerifyCodeResult>;
21
+ declare function sendVerificationCode(email: string): Promise<SendCodeResult>;
22
+ declare function verifyCodeAndSaveToken(email: string, code: string, cookieName?: string): Promise<VerifyCodeResult>;
24
23
  export { sendVerificationCode, verifyCodeAndSaveToken };
25
24
  export type { AuthTokenData, SendCodeResult, VerifyCodeResult };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.verifyCodeAndSaveToken = exports.sendVerificationCode = void 0;
4
+ const authApiClient_1 = require("~/api/authApiClient");
4
5
  const cookieService_1 = require("~/services/cookieService");
5
6
  function validateEmail(email) {
6
7
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -45,7 +46,7 @@ function saveAuthTokenToCookie(token, cookieName = 'auth_token') {
45
46
  const options = createCookieOptions();
46
47
  cookieService_1.cookieService.set(cookieName, token, options);
47
48
  }
48
- async function sendVerificationCode(email, authClient) {
49
+ async function sendVerificationCode(email) {
49
50
  const validation = validateEmailInput(email);
50
51
  if (!validation.valid) {
51
52
  return {
@@ -54,6 +55,7 @@ async function sendVerificationCode(email, authClient) {
54
55
  };
55
56
  }
56
57
  try {
58
+ const authClient = new authApiClient_1.AuthApiClient();
57
59
  const response = await authClient.loginOrSignUpByEmail(email);
58
60
  return {
59
61
  success: true,
@@ -68,7 +70,7 @@ async function sendVerificationCode(email, authClient) {
68
70
  }
69
71
  }
70
72
  exports.sendVerificationCode = sendVerificationCode;
71
- async function verifyCodeAndSaveToken(email, code, authClient, cookieName) {
73
+ async function verifyCodeAndSaveToken(email, code, cookieName) {
72
74
  const validation = validateVerifyInput(email, code);
73
75
  if (!validation.valid) {
74
76
  return {
@@ -78,6 +80,7 @@ async function verifyCodeAndSaveToken(email, code, authClient, cookieName) {
78
80
  };
79
81
  }
80
82
  try {
83
+ const authClient = new authApiClient_1.AuthApiClient();
81
84
  const response = await authClient.verifyCode(email, code);
82
85
  const tokenData = transformVerifyCodeResponse(response);
83
86
  saveAuthTokenToCookie(tokenData.accessToken, cookieName);
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './features/signInOrSignUp';
2
2
  export * from './features/logout';
3
+ export * from './features/getAuthToken';
package/lib/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./features/signInOrSignUp"), exports);
18
18
  __exportStar(require("./features/logout"), exports);
19
+ __exportStar(require("./features/getAuthToken"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveartx/authentication",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "LiveArt authentication package",
5
5
  "files": [
6
6
  "lib/**/*"