@fluoce/auth-react 0.1.1 → 0.1.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.
- package/dist/index.cjs +297 -222
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -70
- package/dist/index.d.ts +41 -70
- package/dist/index.js +300 -226
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/README.md +0 -87
package/dist/index.d.cts
CHANGED
|
@@ -1,82 +1,53 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
interface TokenPair {
|
|
13
|
-
accessToken: string;
|
|
14
|
-
refreshToken: string;
|
|
15
|
-
}
|
|
16
|
-
interface FluoceAuthConfig {
|
|
17
|
-
/** Auth frontend base url, e.g. "https://auth.fluoce.com" */
|
|
18
|
-
authUrl: string;
|
|
19
|
-
/** Auth backend api base url, e.g. "http://localhost:3001" */
|
|
20
|
-
apiUrl: string;
|
|
21
|
-
/**
|
|
22
|
-
* This app's own callback url, sent as `ref` and where auth.fluoce.com
|
|
23
|
-
* redirects back with `?code=`. e.g. "https://myapp.com/auth"
|
|
24
|
-
*/
|
|
25
|
-
appUrl: string;
|
|
26
|
-
accessTokenCookie?: string;
|
|
27
|
-
refreshTokenCookie?: string;
|
|
28
|
-
accessTokenExpiryDays?: number;
|
|
29
|
-
refreshTokenExpiryDays?: number;
|
|
30
|
-
}
|
|
31
|
-
interface FluoceAuthContextValue {
|
|
32
|
-
user: FluoceUser | null;
|
|
33
|
-
loading: boolean;
|
|
34
|
-
isAuthenticated: boolean;
|
|
35
|
-
error: Error | null;
|
|
36
|
-
refreshUser: () => Promise<void>;
|
|
37
|
-
logout: (allDevices?: boolean) => Promise<void>;
|
|
38
|
-
redirectToLogin: () => void;
|
|
39
|
-
}
|
|
4
|
+
type redirect_type = {
|
|
5
|
+
type: "fluoce";
|
|
6
|
+
} | {
|
|
7
|
+
type: "custom";
|
|
8
|
+
redirect: (error: unknown) => void;
|
|
9
|
+
} | {
|
|
10
|
+
type: "none";
|
|
11
|
+
};
|
|
40
12
|
|
|
41
|
-
interface
|
|
13
|
+
interface auth_provider_interface {
|
|
42
14
|
children: ReactNode;
|
|
15
|
+
app_url: string;
|
|
16
|
+
on_error?: () => void;
|
|
17
|
+
redirect?: redirect_type;
|
|
43
18
|
}
|
|
44
|
-
declare function FluoceAuthProvider({ children, ...config }: FluoceAuthProviderProps): react.JSX.Element;
|
|
45
19
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
20
|
+
declare const auth_provider: ({ children, app_url, on_error, redirect, }: auth_provider_interface) => react.JSX.Element;
|
|
21
|
+
|
|
22
|
+
type user_response_type = {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
email: string | null;
|
|
26
|
+
phone: string | null;
|
|
27
|
+
photo: string | null;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type user_type = user_response_type;
|
|
33
|
+
|
|
34
|
+
interface auth_context_interface {
|
|
35
|
+
user: user_response_type | null;
|
|
36
|
+
is_loading: boolean;
|
|
37
|
+
logout(): Promise<boolean>;
|
|
38
|
+
refresh(): Promise<boolean>;
|
|
39
|
+
get_safe_user(): Promise<user_type | null>;
|
|
40
|
+
refresh_token: string | null;
|
|
41
|
+
access_token: string | null;
|
|
50
42
|
}
|
|
51
|
-
declare function AuthGuard({ children, fallback }: AuthGuardProps): react.JSX.Element;
|
|
52
43
|
|
|
53
|
-
declare
|
|
44
|
+
declare const use_auth: () => auth_context_interface;
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/** set by the Provider — called once refresh fails and there's no session left */
|
|
59
|
-
onAuthFailure: () => void;
|
|
60
|
-
constructor(config: FluoceAuthConfig);
|
|
61
|
-
getAccessToken(): string | null;
|
|
62
|
-
getRefreshToken(): string | null;
|
|
63
|
-
setTokens(tokens: TokenPair): void;
|
|
64
|
-
clearTokens(): void;
|
|
65
|
-
buildLoginUrl(): string;
|
|
66
|
-
exchangeCode(code: string): Promise<TokenPair>;
|
|
67
|
-
getMe(): Promise<FluoceUser>;
|
|
68
|
-
updateMe(payload: {
|
|
69
|
-
name?: string;
|
|
70
|
-
photo?: string;
|
|
71
|
-
}): Promise<FluoceUser>;
|
|
72
|
-
refresh(): Promise<TokenPair | null>;
|
|
73
|
-
logout(allDevices?: boolean): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Authenticated fetch. Attaches access token, retries once through /refresh
|
|
76
|
-
* on 401, and calls onAuthFailure (-> redirect to auth frontend) if that
|
|
77
|
-
* fails too. Use this for /me, /me updates, and any endpoint you add later.
|
|
78
|
-
*/
|
|
79
|
-
authFetch<T = unknown>(path: string, init?: RequestInit): Promise<T>;
|
|
46
|
+
interface auth_guard_interface {
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
fallback?: ReactNode;
|
|
80
49
|
}
|
|
81
50
|
|
|
82
|
-
|
|
51
|
+
declare const auth_guard: ({ children, fallback, }: auth_guard_interface) => react.JSX.Element | null;
|
|
52
|
+
|
|
53
|
+
export { auth_guard as FluoceAuthGuard, auth_provider as FluoceAuthProvider, type auth_provider_interface as FluoceAuthProviderType, type redirect_type as FluoceRedirectType, type user_type as FluoceUserType, use_auth as useFluoceAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,53 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
interface TokenPair {
|
|
13
|
-
accessToken: string;
|
|
14
|
-
refreshToken: string;
|
|
15
|
-
}
|
|
16
|
-
interface FluoceAuthConfig {
|
|
17
|
-
/** Auth frontend base url, e.g. "https://auth.fluoce.com" */
|
|
18
|
-
authUrl: string;
|
|
19
|
-
/** Auth backend api base url, e.g. "http://localhost:3001" */
|
|
20
|
-
apiUrl: string;
|
|
21
|
-
/**
|
|
22
|
-
* This app's own callback url, sent as `ref` and where auth.fluoce.com
|
|
23
|
-
* redirects back with `?code=`. e.g. "https://myapp.com/auth"
|
|
24
|
-
*/
|
|
25
|
-
appUrl: string;
|
|
26
|
-
accessTokenCookie?: string;
|
|
27
|
-
refreshTokenCookie?: string;
|
|
28
|
-
accessTokenExpiryDays?: number;
|
|
29
|
-
refreshTokenExpiryDays?: number;
|
|
30
|
-
}
|
|
31
|
-
interface FluoceAuthContextValue {
|
|
32
|
-
user: FluoceUser | null;
|
|
33
|
-
loading: boolean;
|
|
34
|
-
isAuthenticated: boolean;
|
|
35
|
-
error: Error | null;
|
|
36
|
-
refreshUser: () => Promise<void>;
|
|
37
|
-
logout: (allDevices?: boolean) => Promise<void>;
|
|
38
|
-
redirectToLogin: () => void;
|
|
39
|
-
}
|
|
4
|
+
type redirect_type = {
|
|
5
|
+
type: "fluoce";
|
|
6
|
+
} | {
|
|
7
|
+
type: "custom";
|
|
8
|
+
redirect: (error: unknown) => void;
|
|
9
|
+
} | {
|
|
10
|
+
type: "none";
|
|
11
|
+
};
|
|
40
12
|
|
|
41
|
-
interface
|
|
13
|
+
interface auth_provider_interface {
|
|
42
14
|
children: ReactNode;
|
|
15
|
+
app_url: string;
|
|
16
|
+
on_error?: () => void;
|
|
17
|
+
redirect?: redirect_type;
|
|
43
18
|
}
|
|
44
|
-
declare function FluoceAuthProvider({ children, ...config }: FluoceAuthProviderProps): react.JSX.Element;
|
|
45
19
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
20
|
+
declare const auth_provider: ({ children, app_url, on_error, redirect, }: auth_provider_interface) => react.JSX.Element;
|
|
21
|
+
|
|
22
|
+
type user_response_type = {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
email: string | null;
|
|
26
|
+
phone: string | null;
|
|
27
|
+
photo: string | null;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type user_type = user_response_type;
|
|
33
|
+
|
|
34
|
+
interface auth_context_interface {
|
|
35
|
+
user: user_response_type | null;
|
|
36
|
+
is_loading: boolean;
|
|
37
|
+
logout(): Promise<boolean>;
|
|
38
|
+
refresh(): Promise<boolean>;
|
|
39
|
+
get_safe_user(): Promise<user_type | null>;
|
|
40
|
+
refresh_token: string | null;
|
|
41
|
+
access_token: string | null;
|
|
50
42
|
}
|
|
51
|
-
declare function AuthGuard({ children, fallback }: AuthGuardProps): react.JSX.Element;
|
|
52
43
|
|
|
53
|
-
declare
|
|
44
|
+
declare const use_auth: () => auth_context_interface;
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/** set by the Provider — called once refresh fails and there's no session left */
|
|
59
|
-
onAuthFailure: () => void;
|
|
60
|
-
constructor(config: FluoceAuthConfig);
|
|
61
|
-
getAccessToken(): string | null;
|
|
62
|
-
getRefreshToken(): string | null;
|
|
63
|
-
setTokens(tokens: TokenPair): void;
|
|
64
|
-
clearTokens(): void;
|
|
65
|
-
buildLoginUrl(): string;
|
|
66
|
-
exchangeCode(code: string): Promise<TokenPair>;
|
|
67
|
-
getMe(): Promise<FluoceUser>;
|
|
68
|
-
updateMe(payload: {
|
|
69
|
-
name?: string;
|
|
70
|
-
photo?: string;
|
|
71
|
-
}): Promise<FluoceUser>;
|
|
72
|
-
refresh(): Promise<TokenPair | null>;
|
|
73
|
-
logout(allDevices?: boolean): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Authenticated fetch. Attaches access token, retries once through /refresh
|
|
76
|
-
* on 401, and calls onAuthFailure (-> redirect to auth frontend) if that
|
|
77
|
-
* fails too. Use this for /me, /me updates, and any endpoint you add later.
|
|
78
|
-
*/
|
|
79
|
-
authFetch<T = unknown>(path: string, init?: RequestInit): Promise<T>;
|
|
46
|
+
interface auth_guard_interface {
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
fallback?: ReactNode;
|
|
80
49
|
}
|
|
81
50
|
|
|
82
|
-
|
|
51
|
+
declare const auth_guard: ({ children, fallback, }: auth_guard_interface) => react.JSX.Element | null;
|
|
52
|
+
|
|
53
|
+
export { auth_guard as FluoceAuthGuard, auth_provider as FluoceAuthProvider, type auth_provider_interface as FluoceAuthProviderType, type redirect_type as FluoceRedirectType, type user_type as FluoceUserType, use_auth as useFluoceAuth };
|