@ollaid/native-sso 1.0.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.
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Hook d'authentification Native SSO v1.0
3
+ * Architecture Frontend-First avec appels directs à l'IAM
4
+ *
5
+ * @version 1.0.0
6
+ */
7
+ import type { NativeAuthStatus, NativeExchangeResponse, AccountType } from '../types/native';
8
+ export interface UseNativeAuthOptions {
9
+ /** URL du Backend SaaS */
10
+ saasApiUrl: string;
11
+ /** URL du Backend IAM */
12
+ iamApiUrl: string;
13
+ /** Charger les credentials automatiquement au montage */
14
+ autoLoadCredentials?: boolean;
15
+ /** Mode debug */
16
+ debug?: boolean;
17
+ }
18
+ export declare function useNativeAuth(options: UseNativeAuthOptions): {
19
+ credentialsLoaded: boolean;
20
+ processToken: string | null;
21
+ status: NativeAuthStatus | null;
22
+ user: import("..").NativeUser | null;
23
+ application: {
24
+ id: number;
25
+ name: string;
26
+ logo?: string;
27
+ } | null;
28
+ prompt: {
29
+ title: string;
30
+ message: string;
31
+ actions: string[];
32
+ } | null;
33
+ alternativeMethod: {
34
+ type: "email" | "phone";
35
+ value: string;
36
+ } | null;
37
+ conflict: {
38
+ type: "email" | "phone";
39
+ maskedIdentifier: string;
40
+ options: {
41
+ canLogin: boolean;
42
+ canRecoverByEmail: boolean;
43
+ canRecoverBySms: boolean;
44
+ maskedEmail?: string;
45
+ maskedPhone?: string;
46
+ };
47
+ } | null;
48
+ loading: boolean;
49
+ error: string | null;
50
+ errorType: string | null;
51
+ isAuthenticated: boolean;
52
+ accountType: AccountType;
53
+ isPhoneOnly: boolean;
54
+ otpMethod: "email" | "sms" | null | undefined;
55
+ otpSentTo: string | null | undefined;
56
+ loadCredentials: () => Promise<{
57
+ success: boolean;
58
+ error_type?: undefined;
59
+ } | {
60
+ success: boolean;
61
+ error_type: string;
62
+ }>;
63
+ loginWithEmail: (email: string, acctType?: "user" | "admin") => Promise<{
64
+ success: boolean;
65
+ status: string;
66
+ error_type?: undefined;
67
+ } | {
68
+ success: boolean;
69
+ status: NativeAuthStatus | undefined;
70
+ error_type?: undefined;
71
+ } | {
72
+ success: boolean;
73
+ error_type: string | undefined;
74
+ status?: undefined;
75
+ }>;
76
+ loginWithPhone: (ccphone: string, phone: string, acctType?: "user" | "admin") => Promise<{
77
+ success: boolean;
78
+ status: string;
79
+ error_type?: undefined;
80
+ } | {
81
+ success: boolean;
82
+ status: NativeAuthStatus | undefined;
83
+ error_type?: undefined;
84
+ } | {
85
+ success: boolean;
86
+ error_type: string | undefined;
87
+ status?: undefined;
88
+ }>;
89
+ loginWithAccessOtp: (otpCode: string) => Promise<{
90
+ success: boolean;
91
+ status: string;
92
+ callback_token?: undefined;
93
+ error_type?: undefined;
94
+ } | {
95
+ success: boolean;
96
+ status: string;
97
+ callback_token: string;
98
+ error_type?: undefined;
99
+ } | {
100
+ success: boolean;
101
+ status: NativeAuthStatus | undefined;
102
+ callback_token?: undefined;
103
+ error_type?: undefined;
104
+ } | {
105
+ success: boolean;
106
+ error_type: string | undefined;
107
+ status?: undefined;
108
+ callback_token?: undefined;
109
+ }>;
110
+ submitPassword: (password: string) => Promise<{
111
+ success: boolean;
112
+ error: string;
113
+ user?: undefined;
114
+ callback_token?: undefined;
115
+ requires_2fa?: undefined;
116
+ status?: undefined;
117
+ error_type?: undefined;
118
+ } | {
119
+ success: boolean;
120
+ user: import("..").NativeUser;
121
+ callback_token: string;
122
+ error?: undefined;
123
+ requires_2fa?: undefined;
124
+ status?: undefined;
125
+ error_type?: undefined;
126
+ } | {
127
+ success: boolean;
128
+ requires_2fa: boolean;
129
+ error?: undefined;
130
+ user?: undefined;
131
+ callback_token?: undefined;
132
+ status?: undefined;
133
+ error_type?: undefined;
134
+ } | {
135
+ success: boolean;
136
+ status: string;
137
+ error?: undefined;
138
+ user?: undefined;
139
+ callback_token?: undefined;
140
+ requires_2fa?: undefined;
141
+ error_type?: undefined;
142
+ } | {
143
+ success: boolean;
144
+ error_type: string | undefined;
145
+ error?: undefined;
146
+ user?: undefined;
147
+ callback_token?: undefined;
148
+ requires_2fa?: undefined;
149
+ status?: undefined;
150
+ }>;
151
+ submitOtp: (otpCode: string) => Promise<{
152
+ success: boolean;
153
+ error: string;
154
+ user?: undefined;
155
+ callback_token?: undefined;
156
+ status?: undefined;
157
+ error_type?: undefined;
158
+ } | {
159
+ success: boolean;
160
+ user: import("..").NativeUser;
161
+ callback_token: string;
162
+ error?: undefined;
163
+ status?: undefined;
164
+ error_type?: undefined;
165
+ } | {
166
+ success: boolean;
167
+ status: string;
168
+ error?: undefined;
169
+ user?: undefined;
170
+ callback_token?: undefined;
171
+ error_type?: undefined;
172
+ } | {
173
+ success: boolean;
174
+ error_type: string | undefined;
175
+ error?: undefined;
176
+ user?: undefined;
177
+ callback_token?: undefined;
178
+ status?: undefined;
179
+ }>;
180
+ submitTotp: (totpCode: string) => Promise<{
181
+ success: boolean;
182
+ error: string;
183
+ user?: undefined;
184
+ error_type?: undefined;
185
+ } | {
186
+ success: boolean;
187
+ user: import("..").NativeUser;
188
+ error?: undefined;
189
+ error_type?: undefined;
190
+ } | {
191
+ success: boolean;
192
+ error_type: string | undefined;
193
+ error?: undefined;
194
+ user?: undefined;
195
+ }>;
196
+ grantAccess: () => Promise<{
197
+ success: boolean;
198
+ error: string;
199
+ user?: undefined;
200
+ callback_token?: undefined;
201
+ error_type?: undefined;
202
+ } | {
203
+ success: boolean;
204
+ user: import("..").NativeUser;
205
+ callback_token: string;
206
+ error?: undefined;
207
+ error_type?: undefined;
208
+ } | {
209
+ success: boolean;
210
+ error?: undefined;
211
+ user?: undefined;
212
+ callback_token?: undefined;
213
+ error_type?: undefined;
214
+ } | {
215
+ success: boolean;
216
+ error_type: string;
217
+ error?: undefined;
218
+ user?: undefined;
219
+ callback_token?: undefined;
220
+ }>;
221
+ resendOtp: () => Promise<{
222
+ success: boolean;
223
+ error: string;
224
+ cooldown?: undefined;
225
+ message?: undefined;
226
+ otp_code_dev?: undefined;
227
+ } | {
228
+ success: boolean;
229
+ cooldown: number | undefined;
230
+ message: string | undefined;
231
+ otp_code_dev: string | undefined;
232
+ error?: undefined;
233
+ } | {
234
+ success: boolean;
235
+ error?: undefined;
236
+ cooldown?: undefined;
237
+ message?: undefined;
238
+ otp_code_dev?: undefined;
239
+ }>;
240
+ setSession: (data: NativeExchangeResponse) => void;
241
+ logout: () => Promise<void>;
242
+ reset: () => void;
243
+ clearError: () => void;
244
+ register: (data: {
245
+ name: string;
246
+ email?: string;
247
+ ccphone: string;
248
+ phone: string;
249
+ town?: string;
250
+ country?: string;
251
+ }) => Promise<{
252
+ success: boolean;
253
+ status: NativeAuthStatus | undefined;
254
+ error_type?: undefined;
255
+ } | {
256
+ success: boolean;
257
+ error_type: string | undefined;
258
+ status?: undefined;
259
+ }>;
260
+ setAccountType: import("react").Dispatch<import("react").SetStateAction<AccountType>>;
261
+ };
262
+ export default useNativeAuth;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Hook de vérification périodique du token Sanctum
3
+ *
4
+ * - Premier check 2 min après login
5
+ * - Checks suivants toutes les 5 min
6
+ * - Ne déconnecte PAS si offline ou serveur inaccessible
7
+ * - Déconnecte UNIQUEMENT si le backend retourne 401 (token invalide)
8
+ *
9
+ * @version 1.0.0
10
+ */
11
+ import type { UserInfos } from '../types/native';
12
+ export interface UseTokenHealthCheckOptions {
13
+ /** Whether to enable health checks (true when authenticated) */
14
+ enabled: boolean;
15
+ /** SaaS API base URL */
16
+ saasApiUrl: string;
17
+ /** Called when the backend explicitly invalidates the token (401) */
18
+ onTokenInvalid: () => void;
19
+ /** Called when fresh user_infos are received */
20
+ onUserUpdated?: (userInfos: UserInfos) => void;
21
+ /** Debug mode */
22
+ debug?: boolean;
23
+ }
24
+ export declare function useTokenHealthCheck(options: UseTokenHealthCheckOptions): void;
25
+ export default useTokenHealthCheck;