@riligar/auth-react 1.33.0 → 1.35.0

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 CHANGED
@@ -368,35 +368,27 @@ const useAuthStore = zustand.create((set, get) => ({
368
368
  },
369
369
  /* Init ao montar o Provider */
370
370
  init: async () => {
371
- const {
372
- fetchApplicationInfo
373
- } = get();
374
371
  try {
375
- // Buscar application info primeiro (não bloqueia o init)
376
- // Apenas se não estiver em modo interno (dashboard)
377
- if (!isInternal()) {
378
- fetchApplicationInfo();
372
+ // Busca a sessão (que agora também traz applicationInfo)
373
+ const sessionData = await getSession();
374
+
375
+ // Se veio aplicação no redirecionamento/sessão, salva no store
376
+ if (sessionData?.application) {
377
+ set({
378
+ applicationInfo: sessionData.application
379
+ });
379
380
  }
380
381
  let user = null;
381
-
382
- // PRIMEIRO: Tenta buscar sessão do servidor (funciona com cookies)
383
- // Isso é essencial para Better Auth que usa session cookies
384
- try {
385
- const sessionData = await getSession();
386
- if (sessionData?.user) {
387
- user = sessionData.user;
388
- }
389
- if (sessionData?.session) {
390
- set({
391
- currentSession: sessionData.session
392
- });
393
- }
394
- } catch (sessionError) {
395
- // Se falhar (401), continua para verificar localStorage token
396
- console.log('[AuthStore] Server session not found, checking local token');
382
+ if (sessionData?.user) {
383
+ user = sessionData.user;
384
+ }
385
+ if (sessionData?.session) {
386
+ set({
387
+ currentSession: sessionData.session
388
+ });
397
389
  }
398
390
 
399
- // SEGUNDO: Se não encontrou sessão via cookies, verifica localStorage token (JWT)
391
+ // Se não encontrou sessão via cookies, verifica localStorage token (JWT)
400
392
  if (!user && isAuthenticated()) {
401
393
  user = getCurrentUser();
402
394
  }
@@ -2973,6 +2965,157 @@ function UserProfile({
2973
2965
  });
2974
2966
  }
2975
2967
 
2968
+ function UserInformation({
2969
+ user,
2970
+ signOut,
2971
+ onAccountClick,
2972
+ onBillingClick,
2973
+ accountLabel = 'Conta',
2974
+ billingLabel = 'Assinatura',
2975
+ padded = true,
2976
+ size = 'sm',
2977
+ style,
2978
+ ...others
2979
+ }) {
2980
+ if (!user) return null;
2981
+
2982
+ // Size mappings
2983
+ const avatarSizeMap = {
2984
+ sm: 32,
2985
+ md: 40,
2986
+ lg: 48
2987
+ };
2988
+ const fontSizeTitleMap = {
2989
+ sm: 'sm',
2990
+ md: 'md',
2991
+ lg: 'lg'
2992
+ };
2993
+ const fontSizeEmailMap = {
2994
+ sm: '10px',
2995
+ md: 'xs',
2996
+ lg: 'sm'
2997
+ };
2998
+ const btnSizeMap = {
2999
+ sm: 'xs',
3000
+ md: 'sm',
3001
+ lg: 'md'
3002
+ };
3003
+ const gapMap = {
3004
+ sm: 'xs',
3005
+ md: 'sm',
3006
+ lg: 'md'
3007
+ };
3008
+ const widthMap = {
3009
+ sm: 280,
3010
+ md: 320,
3011
+ lg: 400
3012
+ };
3013
+ const name = user.fullName || user.name || 'User';
3014
+ const email = user.primaryEmailAddress || user.email || '';
3015
+ const initials = name.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2);
3016
+ return /*#__PURE__*/jsxRuntime.jsx(core.Box, {
3017
+ p: padded ? gapMap[size] : 0,
3018
+ w: widthMap[size],
3019
+ style: style,
3020
+ ...others,
3021
+ children: /*#__PURE__*/jsxRuntime.jsxs(core.Stack, {
3022
+ gap: gapMap[size],
3023
+ children: [/*#__PURE__*/jsxRuntime.jsxs(core.Group, {
3024
+ wrap: "nowrap",
3025
+ gap: "xs",
3026
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Avatar, {
3027
+ src: user.imageUrl || user.image,
3028
+ size: avatarSizeMap[size],
3029
+ radius: "xl",
3030
+ bg: "gray.1",
3031
+ c: "gray.6",
3032
+ styles: {
3033
+ placeholder: {
3034
+ fontSize: core.rem(avatarSizeMap[size] / 2.2),
3035
+ fontWeight: 600
3036
+ }
3037
+ },
3038
+ children: initials || 'CC'
3039
+ }), /*#__PURE__*/jsxRuntime.jsxs(core.Box, {
3040
+ style: {
3041
+ flex: 1,
3042
+ overflow: 'hidden'
3043
+ },
3044
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Text, {
3045
+ size: fontSizeTitleMap[size],
3046
+ fw: 700,
3047
+ truncate: "end",
3048
+ c: "dark.9",
3049
+ lh: 1.1,
3050
+ children: name
3051
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Text, {
3052
+ size: fontSizeEmailMap[size],
3053
+ c: "gray.5",
3054
+ truncate: "end",
3055
+ lh: 1.1,
3056
+ children: email
3057
+ })]
3058
+ }), /*#__PURE__*/jsxRuntime.jsx(core.ActionIcon, {
3059
+ variant: "subtle",
3060
+ color: "gray.4",
3061
+ size: size,
3062
+ onClick: signOut,
3063
+ children: /*#__PURE__*/jsxRuntime.jsx(iconsReact.IconLogout, {
3064
+ size: avatarSizeMap[size] * 0.45
3065
+ })
3066
+ })]
3067
+ }), /*#__PURE__*/jsxRuntime.jsxs(core.Group, {
3068
+ gap: gapMap[size] === 'xs' ? 6 : 8,
3069
+ grow: true,
3070
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
3071
+ variant: "default",
3072
+ size: btnSizeMap[size],
3073
+ leftSection: /*#__PURE__*/jsxRuntime.jsx(iconsReact.IconSettings, {
3074
+ size: avatarSizeMap[size] * 0.45
3075
+ }),
3076
+ onClick: onAccountClick,
3077
+ fw: 700,
3078
+ fz: gapMap[size] === 'xs' ? "10px" : "xs",
3079
+ radius: "md",
3080
+ children: accountLabel
3081
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
3082
+ variant: "default",
3083
+ size: btnSizeMap[size],
3084
+ leftSection: /*#__PURE__*/jsxRuntime.jsx(iconsReact.IconCreditCard, {
3085
+ size: avatarSizeMap[size] * 0.45
3086
+ }),
3087
+ onClick: onBillingClick,
3088
+ fw: 700,
3089
+ fz: gapMap[size] === 'xs' ? "10px" : "xs",
3090
+ radius: "md",
3091
+ children: billingLabel
3092
+ })]
3093
+ }), /*#__PURE__*/jsxRuntime.jsxs(core.Group, {
3094
+ justify: "center",
3095
+ gap: 4,
3096
+ opacity: 0.3,
3097
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Text, {
3098
+ size: "10px",
3099
+ c: "gray.6",
3100
+ fw: 600,
3101
+ children: "Secured by"
3102
+ }), /*#__PURE__*/jsxRuntime.jsxs(core.Group, {
3103
+ gap: 2,
3104
+ children: [/*#__PURE__*/jsxRuntime.jsx(iconsReact.IconShieldCheck, {
3105
+ size: 10,
3106
+ stroke: 2
3107
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Text, {
3108
+ size: "10px",
3109
+ fw: 800,
3110
+ c: "dark.9",
3111
+ children: "Auth"
3112
+ })]
3113
+ })]
3114
+ })]
3115
+ })
3116
+ });
3117
+ }
3118
+
2976
3119
  /**
2977
3120
  * Renderiza children apenas quando o usuário está autenticado
2978
3121
  * Equivalente ao <SignedIn> do Clerk
@@ -3098,6 +3241,7 @@ exports.SignUpButton = SignUpButton;
3098
3241
  exports.SignUpForm = SignUp;
3099
3242
  exports.SignedIn = SignedIn;
3100
3243
  exports.SignedOut = SignedOut;
3244
+ exports.UserInformation = UserInformation;
3101
3245
  exports.UserProfile = UserProfile;
3102
3246
  exports.VerifyEmail = VerifyEmail;
3103
3247
  exports.VerifyEmailCard = VerifyEmail;