analytica-frontend-lib 1.1.2 → 1.1.3

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.
@@ -4,21 +4,24 @@
4
4
  * @template Tokens - Type for authentication tokens
5
5
  * @template Session - Type for session information
6
6
  * @template Profile - Type for profile information
7
+ * @template User - Type for user information
7
8
  *
8
9
  * @interface UseUrlAuthOptions
9
10
  * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens
10
11
  * @property {(session: Session) => void} setSessionInfo - Function to set session information
11
12
  * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile
13
+ * @property {(user: User) => void} [setUser] - Optional function to set user data
12
14
  * @property {object} api - API instance with get method
13
15
  * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method
14
16
  * @property {string} endpoint - API endpoint to fetch session data
15
17
  * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function
16
18
  * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing
17
19
  */
18
- interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unknown> {
20
+ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown> {
19
21
  setTokens: (tokens: Tokens) => void;
20
22
  setSessionInfo: (session: Session) => void;
21
23
  setSelectedProfile?: (profile: Profile) => void;
24
+ setUser?: (user: User) => void;
22
25
  api: {
23
26
  get: (endpoint: string, config: unknown) => Promise<unknown>;
24
27
  };
@@ -37,8 +40,9 @@ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unkno
37
40
  * @template Tokens - Type for authentication tokens
38
41
  * @template Session - Type for session information
39
42
  * @template Profile - Type for profile information
43
+ * @template User - Type for user information
40
44
  *
41
- * @param {UseUrlAuthOptions<Tokens, Session, Profile>} options - Configuration options
45
+ * @param {UseUrlAuthOptions<Tokens, Session, Profile, User>} options - Configuration options
42
46
  * @returns {void}
43
47
  *
44
48
  * @example
@@ -47,12 +51,13 @@ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unkno
47
51
  * setTokens: (tokens) => authStore.setTokens(tokens),
48
52
  * setSessionInfo: (session) => authStore.setSessionInfo(session),
49
53
  * setSelectedProfile: (profile) => authStore.setProfile(profile),
54
+ * setUser: (user) => authStore.setUser(user),
50
55
  * api: apiInstance,
51
56
  * endpoint: '/auth/session',
52
57
  * clearParamsFromURL: () => navigate('/', { replace: true })
53
58
  * });
54
59
  * ```
55
60
  */
56
- declare function useUrlAuthentication<Tokens = unknown, Session = unknown, Profile = unknown>(options: UseUrlAuthOptions<Tokens, Session, Profile>): void;
61
+ declare function useUrlAuthentication<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown>(options: UseUrlAuthOptions<Tokens, Session, Profile, User>): void;
57
62
 
58
63
  export { type UseUrlAuthOptions, useUrlAuthentication };
@@ -4,21 +4,24 @@
4
4
  * @template Tokens - Type for authentication tokens
5
5
  * @template Session - Type for session information
6
6
  * @template Profile - Type for profile information
7
+ * @template User - Type for user information
7
8
  *
8
9
  * @interface UseUrlAuthOptions
9
10
  * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens
10
11
  * @property {(session: Session) => void} setSessionInfo - Function to set session information
11
12
  * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile
13
+ * @property {(user: User) => void} [setUser] - Optional function to set user data
12
14
  * @property {object} api - API instance with get method
13
15
  * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method
14
16
  * @property {string} endpoint - API endpoint to fetch session data
15
17
  * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function
16
18
  * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing
17
19
  */
18
- interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unknown> {
20
+ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown> {
19
21
  setTokens: (tokens: Tokens) => void;
20
22
  setSessionInfo: (session: Session) => void;
21
23
  setSelectedProfile?: (profile: Profile) => void;
24
+ setUser?: (user: User) => void;
22
25
  api: {
23
26
  get: (endpoint: string, config: unknown) => Promise<unknown>;
24
27
  };
@@ -37,8 +40,9 @@ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unkno
37
40
  * @template Tokens - Type for authentication tokens
38
41
  * @template Session - Type for session information
39
42
  * @template Profile - Type for profile information
43
+ * @template User - Type for user information
40
44
  *
41
- * @param {UseUrlAuthOptions<Tokens, Session, Profile>} options - Configuration options
45
+ * @param {UseUrlAuthOptions<Tokens, Session, Profile, User>} options - Configuration options
42
46
  * @returns {void}
43
47
  *
44
48
  * @example
@@ -47,12 +51,13 @@ interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unkno
47
51
  * setTokens: (tokens) => authStore.setTokens(tokens),
48
52
  * setSessionInfo: (session) => authStore.setSessionInfo(session),
49
53
  * setSelectedProfile: (profile) => authStore.setProfile(profile),
54
+ * setUser: (user) => authStore.setUser(user),
50
55
  * api: apiInstance,
51
56
  * endpoint: '/auth/session',
52
57
  * clearParamsFromURL: () => navigate('/', { replace: true })
53
58
  * });
54
59
  * ```
55
60
  */
56
- declare function useUrlAuthentication<Tokens = unknown, Session = unknown, Profile = unknown>(options: UseUrlAuthOptions<Tokens, Session, Profile>): void;
61
+ declare function useUrlAuthentication<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown>(options: UseUrlAuthOptions<Tokens, Session, Profile, User>): void;
57
62
 
58
63
  export { type UseUrlAuthOptions, useUrlAuthentication };
@@ -50,6 +50,25 @@ var handleProfileSelection = (responseData, setSelectedProfile) => {
50
50
  });
51
51
  }
52
52
  };
53
+ var handleUserData = (responseData, setUser) => {
54
+ if (!setUser) return;
55
+ if (!hasValidProfileData(responseData)) return;
56
+ const userId = responseData.userId;
57
+ const userName = responseData.userName;
58
+ const userEmail = responseData.userEmail;
59
+ if (userId) {
60
+ const userData = {
61
+ id: userId
62
+ };
63
+ if (userName) {
64
+ userData.name = userName;
65
+ }
66
+ if (userEmail) {
67
+ userData.email = userEmail;
68
+ }
69
+ setUser(userData);
70
+ }
71
+ };
53
72
  function useUrlAuthentication(options) {
54
73
  const location = (0, import_react_router_dom.useLocation)();
55
74
  (0, import_react.useEffect)(() => {
@@ -70,6 +89,7 @@ function useUrlAuthentication(options) {
70
89
  });
71
90
  options.setSessionInfo(response.data.data);
72
91
  handleProfileSelection(response.data.data, options.setSelectedProfile);
92
+ handleUserData(response.data.data, options.setUser);
73
93
  options.clearParamsFromURL?.();
74
94
  } catch (error) {
75
95
  console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
@@ -80,6 +100,7 @@ function useUrlAuthentication(options) {
80
100
  location.search,
81
101
  options.setSessionInfo,
82
102
  options.setSelectedProfile,
103
+ options.setUser,
83
104
  options.setTokens,
84
105
  options.api,
85
106
  options.endpoint,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Auth/useUrlAuthentication.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\n/**\n * Options interface for the useUrlAuthentication hook\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n *\n * @interface UseUrlAuthOptions\n * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens\n * @property {(session: Session) => void} setSessionInfo - Function to set session information\n * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @property {object} api - API instance with get method\n * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method\n * @property {string} endpoint - API endpoint to fetch session data\n * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function\n * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing\n */\nexport interface UseUrlAuthOptions<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n> {\n setTokens: (tokens: Tokens) => void;\n setSessionInfo: (session: Session) => void;\n setSelectedProfile?: (profile: Profile) => void;\n api: { get: (endpoint: string, config: unknown) => Promise<unknown> };\n endpoint: string;\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n };\n clearParamsFromURL?: () => void;\n}\n\n/**\n * Helper function to extract authentication parameters from URL\n *\n * @param {object} location - Location object with search property\n * @param {string} location.search - URL search string\n * @param {function} [extractParams] - Custom parameter extraction function\n * @returns {object} Object with sessionId, token, and refreshToken\n *\n * @private\n */\nconst getAuthParams = (\n location: { search: string },\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n }\n) => {\n const searchParams = new URLSearchParams(location.search);\n return extractParams\n ? extractParams(searchParams)\n : {\n sessionId: searchParams.get('sessionId'),\n token: searchParams.get('token'),\n refreshToken: searchParams.get('refreshToken'),\n };\n};\n\n/**\n * Helper function to validate authentication parameters\n *\n * @param {object} authParams - Authentication parameters object\n * @param {string | null} authParams.sessionId - Session ID from URL\n * @param {string | null} authParams.token - Authentication token from URL\n * @param {string | null} authParams.refreshToken - Refresh token from URL\n * @returns {boolean} True if all required parameters are present\n *\n * @private\n */\nconst hasValidAuthParams = (authParams: {\n sessionId: string | null;\n token: string | null;\n refreshToken: string | null;\n}) => {\n return !!(\n authParams?.sessionId &&\n authParams?.token &&\n authParams?.refreshToken\n );\n};\n\n/**\n * Helper function to check if response has valid profile data\n *\n * @param {unknown} data - Response data to validate\n * @returns {data is Record<string, unknown>} Type guard for valid profile data\n *\n * @private\n */\nconst hasValidProfileData = (\n data: unknown\n): data is Record<string, unknown> => {\n return data !== null && typeof data === 'object' && data !== undefined;\n};\n\n/**\n * Helper function to handle profile selection from response data\n *\n * @template Profile - Profile type\n * @param {unknown} responseData - Response data from API\n * @param {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @returns {void}\n *\n * @private\n */\nconst handleProfileSelection = <Profile>(\n responseData: unknown,\n setSelectedProfile?: (profile: Profile) => void\n) => {\n if (!setSelectedProfile) return;\n if (!hasValidProfileData(responseData)) return;\n\n const profileId = responseData.profileId;\n const isValidProfileId = profileId !== null && profileId !== undefined;\n\n if (isValidProfileId) {\n setSelectedProfile({\n id: profileId,\n } as Profile);\n }\n};\n\n/**\n * Hook for handling URL-based authentication\n * Extracts authentication parameters from URL and processes them\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n *\n * @param {UseUrlAuthOptions<Tokens, Session, Profile>} options - Configuration options\n * @returns {void}\n *\n * @example\n * ```typescript\n * useUrlAuthentication({\n * setTokens: (tokens) => authStore.setTokens(tokens),\n * setSessionInfo: (session) => authStore.setSessionInfo(session),\n * setSelectedProfile: (profile) => authStore.setProfile(profile),\n * api: apiInstance,\n * endpoint: '/auth/session',\n * clearParamsFromURL: () => navigate('/', { replace: true })\n * });\n * ```\n */\nexport function useUrlAuthentication<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n>(options: UseUrlAuthOptions<Tokens, Session, Profile>) {\n const location = useLocation();\n\n useEffect(() => {\n /**\n * Main authentication handler that processes URL parameters\n *\n * @returns {Promise<void>}\n * @private\n */\n const handleAuthentication = async () => {\n const authParams = getAuthParams(location, options.extractParams);\n\n if (!hasValidAuthParams(authParams)) {\n return;\n }\n\n try {\n options.setTokens({\n token: authParams.token,\n refreshToken: authParams.refreshToken,\n } as Tokens);\n\n const response = (await options.api.get(options.endpoint, {\n headers: {\n Authorization: `Bearer ${authParams.token}`,\n },\n })) as { data: { data: unknown; [key: string]: unknown } };\n\n options.setSessionInfo(response.data.data as Session);\n handleProfileSelection(response.data.data, options.setSelectedProfile);\n options.clearParamsFromURL?.();\n } catch (error) {\n console.error('Erro ao obter informações da sessão:', error);\n }\n };\n\n handleAuthentication();\n }, [\n location.search,\n options.setSessionInfo,\n options.setSelectedProfile,\n options.setTokens,\n options.api,\n options.endpoint,\n options.extractParams,\n options.clearParamsFromURL,\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B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AAQ,qBAAqB;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAwC,KAAK;AAAA,MAC7D;AAAA,IACF;AAEA,yBAAqB;AAAA,EACvB,GAAG;AAAA,IACD,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/Auth/useUrlAuthentication.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\n/**\n * Options interface for the useUrlAuthentication hook\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n * @template User - Type for user information\n *\n * @interface UseUrlAuthOptions\n * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens\n * @property {(session: Session) => void} setSessionInfo - Function to set session information\n * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @property {(user: User) => void} [setUser] - Optional function to set user data\n * @property {object} api - API instance with get method\n * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method\n * @property {string} endpoint - API endpoint to fetch session data\n * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function\n * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing\n */\nexport interface UseUrlAuthOptions<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n User = unknown,\n> {\n setTokens: (tokens: Tokens) => void;\n setSessionInfo: (session: Session) => void;\n setSelectedProfile?: (profile: Profile) => void;\n setUser?: (user: User) => void;\n api: { get: (endpoint: string, config: unknown) => Promise<unknown> };\n endpoint: string;\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n };\n clearParamsFromURL?: () => void;\n}\n\n/**\n * Helper function to extract authentication parameters from URL\n *\n * @param {object} location - Location object with search property\n * @param {string} location.search - URL search string\n * @param {function} [extractParams] - Custom parameter extraction function\n * @returns {object} Object with sessionId, token, and refreshToken\n *\n * @private\n */\nconst getAuthParams = (\n location: { search: string },\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n }\n) => {\n const searchParams = new URLSearchParams(location.search);\n return extractParams\n ? extractParams(searchParams)\n : {\n sessionId: searchParams.get('sessionId'),\n token: searchParams.get('token'),\n refreshToken: searchParams.get('refreshToken'),\n };\n};\n\n/**\n * Helper function to validate authentication parameters\n *\n * @param {object} authParams - Authentication parameters object\n * @param {string | null} authParams.sessionId - Session ID from URL\n * @param {string | null} authParams.token - Authentication token from URL\n * @param {string | null} authParams.refreshToken - Refresh token from URL\n * @returns {boolean} True if all required parameters are present\n *\n * @private\n */\nconst hasValidAuthParams = (authParams: {\n sessionId: string | null;\n token: string | null;\n refreshToken: string | null;\n}) => {\n return !!(\n authParams?.sessionId &&\n authParams?.token &&\n authParams?.refreshToken\n );\n};\n\n/**\n * Helper function to check if response has valid profile data\n *\n * @param {unknown} data - Response data to validate\n * @returns {data is Record<string, unknown>} Type guard for valid profile data\n *\n * @private\n */\nconst hasValidProfileData = (\n data: unknown\n): data is Record<string, unknown> => {\n return data !== null && typeof data === 'object' && data !== undefined;\n};\n\n/**\n * Helper function to handle profile selection from response data\n *\n * @template Profile - Profile type\n * @param {unknown} responseData - Response data from API\n * @param {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @returns {void}\n *\n * @private\n */\nconst handleProfileSelection = <Profile>(\n responseData: unknown,\n setSelectedProfile?: (profile: Profile) => void\n) => {\n if (!setSelectedProfile) return;\n if (!hasValidProfileData(responseData)) return;\n\n const profileId = responseData.profileId;\n const isValidProfileId = profileId !== null && profileId !== undefined;\n\n if (isValidProfileId) {\n setSelectedProfile({\n id: profileId,\n } as Profile);\n }\n};\n\n/**\n * Helper function to handle user data extraction from response data\n *\n * @template User - User type\n * @param {unknown} responseData - Response data from API\n * @param {(user: User) => void} [setUser] - Optional function to set user data\n * @returns {void}\n *\n * @private\n */\nconst handleUserData = <User>(\n responseData: unknown,\n setUser?: (user: User) => void\n) => {\n if (!setUser) return;\n if (!hasValidProfileData(responseData)) return;\n\n // Extrair dados do usuário da resposta da API\n const userId = responseData.userId;\n const userName = responseData.userName;\n const userEmail = responseData.userEmail;\n\n if (userId) {\n const userData: Record<string, unknown> = {\n id: userId,\n };\n\n if (userName) {\n userData.name = userName;\n }\n\n if (userEmail) {\n userData.email = userEmail;\n }\n\n // Adicionar outros campos conforme necessário\n setUser(userData as User);\n }\n};\n\n/**\n * Hook for handling URL-based authentication\n * Extracts authentication parameters from URL and processes them\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n * @template User - Type for user information\n *\n * @param {UseUrlAuthOptions<Tokens, Session, Profile, User>} options - Configuration options\n * @returns {void}\n *\n * @example\n * ```typescript\n * useUrlAuthentication({\n * setTokens: (tokens) => authStore.setTokens(tokens),\n * setSessionInfo: (session) => authStore.setSessionInfo(session),\n * setSelectedProfile: (profile) => authStore.setProfile(profile),\n * setUser: (user) => authStore.setUser(user),\n * api: apiInstance,\n * endpoint: '/auth/session',\n * clearParamsFromURL: () => navigate('/', { replace: true })\n * });\n * ```\n */\nexport function useUrlAuthentication<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n User = unknown,\n>(options: UseUrlAuthOptions<Tokens, Session, Profile, User>) {\n const location = useLocation();\n\n useEffect(() => {\n /**\n * Main authentication handler that processes URL parameters\n *\n * @returns {Promise<void>}\n * @private\n */\n const handleAuthentication = async () => {\n const authParams = getAuthParams(location, options.extractParams);\n\n if (!hasValidAuthParams(authParams)) {\n return;\n }\n\n try {\n options.setTokens({\n token: authParams.token,\n refreshToken: authParams.refreshToken,\n } as Tokens);\n\n const response = (await options.api.get(options.endpoint, {\n headers: {\n Authorization: `Bearer ${authParams.token}`,\n },\n })) as { data: { data: unknown; [key: string]: unknown } };\n\n options.setSessionInfo(response.data.data as Session);\n handleProfileSelection(response.data.data, options.setSelectedProfile);\n handleUserData(response.data.data, options.setUser);\n options.clearParamsFromURL?.();\n } catch (error) {\n console.error('Erro ao obter informações da sessão:', error);\n }\n };\n\n handleAuthentication();\n }, [\n location.search,\n options.setSessionInfo,\n options.setSelectedProfile,\n options.setUser,\n options.setTokens,\n options.api,\n options.endpoint,\n options.extractParams,\n options.clearParamsFromURL,\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,8BAA4B;AAmD5B,IAAM,gBAAgB,CACpB,UACA,kBAKG;AACH,QAAM,eAAe,IAAI,gBAAgB,SAAS,MAAM;AACxD,SAAO,gBACH,cAAc,YAAY,IAC1B;AAAA,IACE,WAAW,aAAa,IAAI,WAAW;AAAA,IACvC,OAAO,aAAa,IAAI,OAAO;AAAA,IAC/B,cAAc,aAAa,IAAI,cAAc;AAAA,EAC/C;AACN;AAaA,IAAM,qBAAqB,CAAC,eAItB;AACJ,SAAO,CAAC,EACN,YAAY,aACZ,YAAY,SACZ,YAAY;AAEhB;AAUA,IAAM,sBAAsB,CAC1B,SACoC;AACpC,SAAO,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS;AAC/D;AAYA,IAAM,yBAAyB,CAC7B,cACA,uBACG;AACH,MAAI,CAAC,mBAAoB;AACzB,MAAI,CAAC,oBAAoB,YAAY,EAAG;AAExC,QAAM,YAAY,aAAa;AAC/B,QAAM,mBAAmB,cAAc,QAAQ,cAAc;AAE7D,MAAI,kBAAkB;AACpB,uBAAmB;AAAA,MACjB,IAAI;AAAA,IACN,CAAY;AAAA,EACd;AACF;AAYA,IAAM,iBAAiB,CACrB,cACA,YACG;AACH,MAAI,CAAC,QAAS;AACd,MAAI,CAAC,oBAAoB,YAAY,EAAG;AAGxC,QAAM,SAAS,aAAa;AAC5B,QAAM,WAAW,aAAa;AAC9B,QAAM,YAAY,aAAa;AAE/B,MAAI,QAAQ;AACV,UAAM,WAAoC;AAAA,MACxC,IAAI;AAAA,IACN;AAEA,QAAI,UAAU;AACZ,eAAS,OAAO;AAAA,IAClB;AAEA,QAAI,WAAW;AACb,eAAS,QAAQ;AAAA,IACnB;AAGA,YAAQ,QAAgB;AAAA,EAC1B;AACF;AA2BO,SAAS,qBAKd,SAA4D;AAC5D,QAAM,eAAW,qCAAY;AAE7B,8BAAU,MAAM;AAOd,UAAM,uBAAuB,YAAY;AACvC,YAAM,aAAa,cAAc,UAAU,QAAQ,aAAa;AAEhE,UAAI,CAAC,mBAAmB,UAAU,GAAG;AACnC;AAAA,MACF;AAEA,UAAI;AACF,gBAAQ,UAAU;AAAA,UAChB,OAAO,WAAW;AAAA,UAClB,cAAc,WAAW;AAAA,QAC3B,CAAW;AAEX,cAAM,WAAY,MAAM,QAAQ,IAAI,IAAI,QAAQ,UAAU;AAAA,UACxD,SAAS;AAAA,YACP,eAAe,UAAU,WAAW,KAAK;AAAA,UAC3C;AAAA,QACF,CAAC;AAED,gBAAQ,eAAe,SAAS,KAAK,IAAe;AACpD,+BAAuB,SAAS,KAAK,MAAM,QAAQ,kBAAkB;AACrE,uBAAe,SAAS,KAAK,MAAM,QAAQ,OAAO;AAClD,gBAAQ,qBAAqB;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAwC,KAAK;AAAA,MAC7D;AAAA,IACF;AAEA,yBAAqB;AAAA,EACvB,GAAG;AAAA,IACD,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AACH;","names":[]}
@@ -26,6 +26,25 @@ var handleProfileSelection = (responseData, setSelectedProfile) => {
26
26
  });
27
27
  }
28
28
  };
29
+ var handleUserData = (responseData, setUser) => {
30
+ if (!setUser) return;
31
+ if (!hasValidProfileData(responseData)) return;
32
+ const userId = responseData.userId;
33
+ const userName = responseData.userName;
34
+ const userEmail = responseData.userEmail;
35
+ if (userId) {
36
+ const userData = {
37
+ id: userId
38
+ };
39
+ if (userName) {
40
+ userData.name = userName;
41
+ }
42
+ if (userEmail) {
43
+ userData.email = userEmail;
44
+ }
45
+ setUser(userData);
46
+ }
47
+ };
29
48
  function useUrlAuthentication(options) {
30
49
  const location = useLocation();
31
50
  useEffect(() => {
@@ -46,6 +65,7 @@ function useUrlAuthentication(options) {
46
65
  });
47
66
  options.setSessionInfo(response.data.data);
48
67
  handleProfileSelection(response.data.data, options.setSelectedProfile);
68
+ handleUserData(response.data.data, options.setUser);
49
69
  options.clearParamsFromURL?.();
50
70
  } catch (error) {
51
71
  console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
@@ -56,6 +76,7 @@ function useUrlAuthentication(options) {
56
76
  location.search,
57
77
  options.setSessionInfo,
58
78
  options.setSelectedProfile,
79
+ options.setUser,
59
80
  options.setTokens,
60
81
  options.api,
61
82
  options.endpoint,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Auth/useUrlAuthentication.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\n/**\n * Options interface for the useUrlAuthentication hook\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n *\n * @interface UseUrlAuthOptions\n * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens\n * @property {(session: Session) => void} setSessionInfo - Function to set session information\n * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @property {object} api - API instance with get method\n * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method\n * @property {string} endpoint - API endpoint to fetch session data\n * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function\n * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing\n */\nexport interface UseUrlAuthOptions<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n> {\n setTokens: (tokens: Tokens) => void;\n setSessionInfo: (session: Session) => void;\n setSelectedProfile?: (profile: Profile) => void;\n api: { get: (endpoint: string, config: unknown) => Promise<unknown> };\n endpoint: string;\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n };\n clearParamsFromURL?: () => void;\n}\n\n/**\n * Helper function to extract authentication parameters from URL\n *\n * @param {object} location - Location object with search property\n * @param {string} location.search - URL search string\n * @param {function} [extractParams] - Custom parameter extraction function\n * @returns {object} Object with sessionId, token, and refreshToken\n *\n * @private\n */\nconst getAuthParams = (\n location: { search: string },\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n }\n) => {\n const searchParams = new URLSearchParams(location.search);\n return extractParams\n ? extractParams(searchParams)\n : {\n sessionId: searchParams.get('sessionId'),\n token: searchParams.get('token'),\n refreshToken: searchParams.get('refreshToken'),\n };\n};\n\n/**\n * Helper function to validate authentication parameters\n *\n * @param {object} authParams - Authentication parameters object\n * @param {string | null} authParams.sessionId - Session ID from URL\n * @param {string | null} authParams.token - Authentication token from URL\n * @param {string | null} authParams.refreshToken - Refresh token from URL\n * @returns {boolean} True if all required parameters are present\n *\n * @private\n */\nconst hasValidAuthParams = (authParams: {\n sessionId: string | null;\n token: string | null;\n refreshToken: string | null;\n}) => {\n return !!(\n authParams?.sessionId &&\n authParams?.token &&\n authParams?.refreshToken\n );\n};\n\n/**\n * Helper function to check if response has valid profile data\n *\n * @param {unknown} data - Response data to validate\n * @returns {data is Record<string, unknown>} Type guard for valid profile data\n *\n * @private\n */\nconst hasValidProfileData = (\n data: unknown\n): data is Record<string, unknown> => {\n return data !== null && typeof data === 'object' && data !== undefined;\n};\n\n/**\n * Helper function to handle profile selection from response data\n *\n * @template Profile - Profile type\n * @param {unknown} responseData - Response data from API\n * @param {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @returns {void}\n *\n * @private\n */\nconst handleProfileSelection = <Profile>(\n responseData: unknown,\n setSelectedProfile?: (profile: Profile) => void\n) => {\n if (!setSelectedProfile) return;\n if (!hasValidProfileData(responseData)) return;\n\n const profileId = responseData.profileId;\n const isValidProfileId = profileId !== null && profileId !== undefined;\n\n if (isValidProfileId) {\n setSelectedProfile({\n id: profileId,\n } as Profile);\n }\n};\n\n/**\n * Hook for handling URL-based authentication\n * Extracts authentication parameters from URL and processes them\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n *\n * @param {UseUrlAuthOptions<Tokens, Session, Profile>} options - Configuration options\n * @returns {void}\n *\n * @example\n * ```typescript\n * useUrlAuthentication({\n * setTokens: (tokens) => authStore.setTokens(tokens),\n * setSessionInfo: (session) => authStore.setSessionInfo(session),\n * setSelectedProfile: (profile) => authStore.setProfile(profile),\n * api: apiInstance,\n * endpoint: '/auth/session',\n * clearParamsFromURL: () => navigate('/', { replace: true })\n * });\n * ```\n */\nexport function useUrlAuthentication<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n>(options: UseUrlAuthOptions<Tokens, Session, Profile>) {\n const location = useLocation();\n\n useEffect(() => {\n /**\n * Main authentication handler that processes URL parameters\n *\n * @returns {Promise<void>}\n * @private\n */\n const handleAuthentication = async () => {\n const authParams = getAuthParams(location, options.extractParams);\n\n if (!hasValidAuthParams(authParams)) {\n return;\n }\n\n try {\n options.setTokens({\n token: authParams.token,\n refreshToken: authParams.refreshToken,\n } as Tokens);\n\n const response = (await options.api.get(options.endpoint, {\n headers: {\n Authorization: `Bearer ${authParams.token}`,\n },\n })) as { data: { data: unknown; [key: string]: unknown } };\n\n options.setSessionInfo(response.data.data as Session);\n handleProfileSelection(response.data.data, options.setSelectedProfile);\n options.clearParamsFromURL?.();\n } catch (error) {\n console.error('Erro ao obter informações da sessão:', error);\n }\n };\n\n handleAuthentication();\n }, [\n location.search,\n options.setSessionInfo,\n options.setSelectedProfile,\n options.setTokens,\n options.api,\n options.end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e,SAAS,KAAK,IAAe;AACpD,+BAAuB,SAAS,KAAK,MAAM,QAAQ,kBAAkB;AACrE,gBAAQ,qBAAqB;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,iDAAwC,KAAK;AAAA,MAC7D;AAAA,IACF;AAEA,yBAAqB;AAAA,EACvB,GAAG;AAAA,IACD,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/Auth/useUrlAuthentication.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\n/**\n * Options interface for the useUrlAuthentication hook\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n * @template User - Type for user information\n *\n * @interface UseUrlAuthOptions\n * @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens\n * @property {(session: Session) => void} setSessionInfo - Function to set session information\n * @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @property {(user: User) => void} [setUser] - Optional function to set user data\n * @property {object} api - API instance with get method\n * @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method\n * @property {string} endpoint - API endpoint to fetch session data\n * @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function\n * @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing\n */\nexport interface UseUrlAuthOptions<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n User = unknown,\n> {\n setTokens: (tokens: Tokens) => void;\n setSessionInfo: (session: Session) => void;\n setSelectedProfile?: (profile: Profile) => void;\n setUser?: (user: User) => void;\n api: { get: (endpoint: string, config: unknown) => Promise<unknown> };\n endpoint: string;\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n };\n clearParamsFromURL?: () => void;\n}\n\n/**\n * Helper function to extract authentication parameters from URL\n *\n * @param {object} location - Location object with search property\n * @param {string} location.search - URL search string\n * @param {function} [extractParams] - Custom parameter extraction function\n * @returns {object} Object with sessionId, token, and refreshToken\n *\n * @private\n */\nconst getAuthParams = (\n location: { search: string },\n extractParams?: (searchParams: URLSearchParams) => {\n sessionId: string;\n token: string;\n refreshToken: string;\n }\n) => {\n const searchParams = new URLSearchParams(location.search);\n return extractParams\n ? extractParams(searchParams)\n : {\n sessionId: searchParams.get('sessionId'),\n token: searchParams.get('token'),\n refreshToken: searchParams.get('refreshToken'),\n };\n};\n\n/**\n * Helper function to validate authentication parameters\n *\n * @param {object} authParams - Authentication parameters object\n * @param {string | null} authParams.sessionId - Session ID from URL\n * @param {string | null} authParams.token - Authentication token from URL\n * @param {string | null} authParams.refreshToken - Refresh token from URL\n * @returns {boolean} True if all required parameters are present\n *\n * @private\n */\nconst hasValidAuthParams = (authParams: {\n sessionId: string | null;\n token: string | null;\n refreshToken: string | null;\n}) => {\n return !!(\n authParams?.sessionId &&\n authParams?.token &&\n authParams?.refreshToken\n );\n};\n\n/**\n * Helper function to check if response has valid profile data\n *\n * @param {unknown} data - Response data to validate\n * @returns {data is Record<string, unknown>} Type guard for valid profile data\n *\n * @private\n */\nconst hasValidProfileData = (\n data: unknown\n): data is Record<string, unknown> => {\n return data !== null && typeof data === 'object' && data !== undefined;\n};\n\n/**\n * Helper function to handle profile selection from response data\n *\n * @template Profile - Profile type\n * @param {unknown} responseData - Response data from API\n * @param {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile\n * @returns {void}\n *\n * @private\n */\nconst handleProfileSelection = <Profile>(\n responseData: unknown,\n setSelectedProfile?: (profile: Profile) => void\n) => {\n if (!setSelectedProfile) return;\n if (!hasValidProfileData(responseData)) return;\n\n const profileId = responseData.profileId;\n const isValidProfileId = profileId !== null && profileId !== undefined;\n\n if (isValidProfileId) {\n setSelectedProfile({\n id: profileId,\n } as Profile);\n }\n};\n\n/**\n * Helper function to handle user data extraction from response data\n *\n * @template User - User type\n * @param {unknown} responseData - Response data from API\n * @param {(user: User) => void} [setUser] - Optional function to set user data\n * @returns {void}\n *\n * @private\n */\nconst handleUserData = <User>(\n responseData: unknown,\n setUser?: (user: User) => void\n) => {\n if (!setUser) return;\n if (!hasValidProfileData(responseData)) return;\n\n // Extrair dados do usuário da resposta da API\n const userId = responseData.userId;\n const userName = responseData.userName;\n const userEmail = responseData.userEmail;\n\n if (userId) {\n const userData: Record<string, unknown> = {\n id: userId,\n };\n\n if (userName) {\n userData.name = userName;\n }\n\n if (userEmail) {\n userData.email = userEmail;\n }\n\n // Adicionar outros campos conforme necessário\n setUser(userData as User);\n }\n};\n\n/**\n * Hook for handling URL-based authentication\n * Extracts authentication parameters from URL and processes them\n *\n * @template Tokens - Type for authentication tokens\n * @template Session - Type for session information\n * @template Profile - Type for profile information\n * @template User - Type for user information\n *\n * @param {UseUrlAuthOptions<Tokens, Session, Profile, User>} options - Configuration options\n * @returns {void}\n *\n * @example\n * ```typescript\n * useUrlAuthentication({\n * setTokens: (tokens) => authStore.setTokens(tokens),\n * setSessionInfo: (session) => authStore.setSessionInfo(session),\n * setSelectedProfile: (profile) => authStore.setProfile(profile),\n * setUser: (user) => authStore.setUser(user),\n * api: apiInstance,\n * endpoint: '/auth/session',\n * clearParamsFromURL: () => navigate('/', { replace: true })\n * });\n * ```\n */\nexport function useUrlAuthentication<\n Tokens = unknown,\n Session = unknown,\n Profile = unknown,\n User = unknown,\n>(options: UseUrlAuthOptions<Tokens, Session, Profile, User>) {\n const location = useLocation();\n\n useEffect(() => {\n /**\n * Main authentication handler that processes URL parameters\n *\n * @returns {Promise<void>}\n * @private\n */\n const handleAuthentication = async () => {\n const authParams = getAuthParams(location, options.extractParams);\n\n if (!hasValidAuthParams(authParams)) {\n return;\n }\n\n try {\n options.setTokens({\n token: authParams.token,\n refreshToken: authParams.refreshToken,\n } as Tokens);\n\n const response = (await options.api.get(options.endpoint, {\n headers: {\n Authorization: `Bearer ${authParams.token}`,\n },\n })) as { data: { data: unknown; [key: string]: unknown } };\n\n options.setSessionInfo(response.data.data as Session);\n handleProfileSelection(response.data.data, options.setSelectedProfile);\n handleUserData(response.data.data, options.setUser);\n options.clearParamsFromURL?.();\n } catch (error) {\n console.error('Erro ao obter informações da sessão:', error);\n }\n };\n\n handleAuthentication();\n }, [\n location.search,\n options.setSessionInfo,\n options.setSelectedProfile,\n options.setUser,\n options.setTokens,\n options.api,\n options.endpoint,\n options.extractParams,\n options.clearParamsFromURL,\n ]);\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAmD5B,IAAM,gBAAgB,CACpB,UACA,kBAKG;AACH,QAAM,eAAe,IAAI,gBAAgB,SAAS,MAAM;AACxD,SAAO,gBACH,cAAc,YAAY,IAC1B;AAAA,IACE,WAAW,aAAa,IAAI,WAAW;AAAA,IACvC,OAAO,aAAa,IAAI,OAAO;AAAA,IAC/B,cAAc,aAAa,IAAI,cAAc;AAAA,EAC/C;AACN;AAaA,IAAM,qBAAqB,CAAC,eAItB;AACJ,SAAO,CAAC,EACN,YAAY,aACZ,YAAY,SACZ,YAAY;AAEhB;AAUA,IAAM,sBAAsB,CAC1B,SACoC;AACpC,SAAO,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS;AAC/D;AAYA,IAAM,yBAAyB,CAC7B,cACA,uBACG;AACH,MAAI,CAAC,mBAAoB;AACzB,MAAI,CAAC,oBAAoB,YAAY,EAAG;AAExC,QAAM,YAAY,aAAa;AAC/B,QAAM,mBAAmB,cAAc,QAAQ,cAAc;AAE7D,MAAI,kBAAkB;AACpB,uBAAmB;AAAA,MACjB,IAAI;AAAA,IACN,CAAY;AAAA,EACd;AACF;AAYA,IAAM,iBAAiB,CACrB,cACA,YACG;AACH,MAAI,CAAC,QAAS;AACd,MAAI,CAAC,oBAAoB,YAAY,EAAG;AAGxC,QAAM,SAAS,aAAa;AAC5B,QAAM,WAA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  };
7094
+ var handleUserData = (responseData, setUser) => {
7095
+ if (!setUser) return;
7096
+ if (!hasValidProfileData(responseData)) return;
7097
+ const userId = responseData.userId;
7098
+ const userName = responseData.userName;
7099
+ const userEmail = responseData.userEmail;
7100
+ if (userId) {
7101
+ const userData = {
7102
+ id: userId
7103
+ };
7104
+ if (userName) {
7105
+ userData.name = userName;
7106
+ }
7107
+ if (userEmail) {
7108
+ userData.email = userEmail;
7109
+ }
7110
+ setUser(userData);
7111
+ }
7112
+ };
7094
7113
  function useUrlAuthentication(options) {
7095
7114
  const location = (0, import_react_router_dom2.useLocation)();
7096
7115
  (0, import_react23.useEffect)(() => {
@@ -7111,6 +7130,7 @@ function useUrlAuthentication(options) {
7111
7130
  });
7112
7131
  options.setSessionInfo(response.data.data);
7113
7132
  handleProfileSelection(response.data.data, options.setSelectedProfile);
7133
+ handleUserData(response.data.data, options.setUser);
7114
7134
  options.clearParamsFromURL?.();
7115
7135
  } catch (error) {
7116
7136
  console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
@@ -7121,6 +7141,7 @@ function useUrlAuthentication(options) {
7121
7141
  location.search,
7122
7142
  options.setSessionInfo,
7123
7143
  options.setSelectedProfile,
7144
+ options.setUser,
7124
7145
  options.setTokens,
7125
7146
  options.api,
7126
7147
  options.endpoint,