@trimble-oss/trimble-id-react 0.0.1-rc.1

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,70 @@
1
+ import { TIDAuthToken, TIDUser } from '../../interfaces';
2
+ export type PersistentStore = 'in-memory' | 'localStorage' | 'sessionStorage';
3
+ export interface CacheManagerOptions {
4
+ /**
5
+ * Client id of the application created in trimble developer console
6
+ * @type {string}
7
+ */
8
+ clientId: string;
9
+ /**
10
+ * Type persistent you want the user and token to be store
11
+ * in-memory - This one will only persist will the user stays in the page
12
+ * localStorage - This persistent doesn't have expiration date
13
+ * sessionStorage - This one is cleared when the page session ends
14
+ * @type {PersistentStore}
15
+ */
16
+ persistentStore: PersistentStore;
17
+ }
18
+ /** Class to manage the store types */
19
+ export declare class CacheManager {
20
+ /**
21
+ * Type persistent you want the user and token to be store
22
+ * in-memory - This one will only persist will the user stays in the page
23
+ * localStorage - This persistent doesn't have expiration date
24
+ * sessionStorage - This one is cleared when the page session ends
25
+ * @type {PersistentStore}
26
+ */
27
+ private readonly persistentStore;
28
+ /**
29
+ * Cache option selected
30
+ * @type {CacheStorage}
31
+ */
32
+ private readonly cacheStorage;
33
+ /**
34
+ * The cache key represents the keys for storing and retrieving user and token from auth
35
+ * @type {CacheKey}
36
+ */
37
+ private readonly cacheKey;
38
+ /**
39
+ * Create a cache manager to extract or save the user, and token
40
+ * @param {CacheManagerOptions} options - Configuration for the managing the caching
41
+ */
42
+ constructor(options: CacheManagerOptions);
43
+ /**
44
+ * Store token in cache
45
+ * @param {TIDAuthToken} token - Token that you want to store in cache
46
+ * @return {Promise<void>} Empty promise
47
+ */
48
+ setToken(token: TIDAuthToken): Promise<void>;
49
+ /**
50
+ * Store user in cache
51
+ * @param {TIDUser} user - User that you want to store in cache
52
+ * @return {Promise<void>} Empty promise
53
+ */
54
+ setUser(user: TIDUser): Promise<void>;
55
+ /**
56
+ * Get user store in cache
57
+ * @return {Promise<TIDUser | undefined>} Key for the user
58
+ */
59
+ getUser(): Promise<TIDUser | undefined>;
60
+ /**
61
+ * Get token store in cache
62
+ * @return {Promise<TIDAuthToken | undefined>} Key for the user
63
+ */
64
+ getToken(): Promise<TIDAuthToken | undefined>;
65
+ /**
66
+ * The clear the cache from the storage
67
+ * @return {Promise<void>} Empty promise
68
+ */
69
+ clear(): Promise<void>;
70
+ }
@@ -0,0 +1,12 @@
1
+ import { CacheStorage } from '../../interfaces';
2
+ /** Class representing in-memory caching store */
3
+ export declare class InMemoryCache {
4
+ /**
5
+ * This function generate a encapsulation function to store
6
+ * the user and token information in a secure way disabled the
7
+ * access from the outside
8
+ * @see {https://medium.com/javascript-scene/encapsulation-in-javascript-26be60e325b4} Encapsulation
9
+ * @return {CacheStorage} Key for the token
10
+ */
11
+ generateCache: CacheStorage;
12
+ }
@@ -0,0 +1,67 @@
1
+ import { CacheStorage, TIDAuthToken, TIDUser } from '../../interfaces';
2
+ import { CacheKey } from './CacheKey';
3
+ export interface LocalStorageCacheOptions {
4
+ /**
5
+ * The cache key represents the keys for storing and retrieving user and token from auth
6
+ * @type {CacheKey}
7
+ */
8
+ cacheKey: CacheKey;
9
+ }
10
+ /**
11
+ * Class representing localstorage caching
12
+ * NOTE: This type storage do not expired so it will persist even if the user close the browser
13
+ */
14
+ export declare class LocalStorageCache implements CacheStorage {
15
+ /**
16
+ * Local storage from the browser
17
+ * @type {Storage}
18
+ */
19
+ private readonly localStorage;
20
+ /**
21
+ * The cache key represents the keys for storing and retrieving user and token from auth
22
+ * @type {CacheKey}
23
+ */
24
+ private readonly cacheKey;
25
+ /**
26
+ * Initialized configuration to store information into local storage
27
+ * @param {LocalStorageCacheOptions} options - Configuration for caching in localstorage
28
+ */
29
+ constructor(options: LocalStorageCacheOptions);
30
+ /**
31
+ * Get token store in localstorage
32
+ * @return {Promise<TIDAuthToken | undefined>} - Token store in localstorage
33
+ */
34
+ getToken(): Promise<TIDAuthToken | undefined>;
35
+ /**
36
+ * Get user store in localstorage
37
+ * @return {Promise<TIDUser | undefined>} - User store in localstorage
38
+ */
39
+ getUser(): Promise<TIDUser | undefined>;
40
+ /**
41
+ * Store token in localstorage
42
+ * @param {TIDAuthToken} token - Token that you want to store in localstorage
43
+ * @return {Promise<void>} Empty promise
44
+ */
45
+ storeToken(authToken: TIDAuthToken): Promise<void>;
46
+ /**
47
+ * Store user in cache
48
+ * @param {TIDUser} user - User that you want to store in localstorage
49
+ * @return {Promise<void>} Empty promise
50
+ */
51
+ storeUser(user: TIDUser): Promise<void>;
52
+ /**
53
+ * Get the full key from the cachekey for the user
54
+ * @return {string} - Full key to get the token from the localstorage
55
+ */
56
+ getUserKey(): string;
57
+ /**
58
+ * Get the full key from the cachekey for the token
59
+ * @return {string} - Full key to get the token from the localstorage
60
+ */
61
+ getAuthKey(): string;
62
+ /**
63
+ * The clear the cache from the localstorage
64
+ * @return {Promise<void>} Empty promise
65
+ */
66
+ clear(): Promise<void>;
67
+ }
@@ -0,0 +1,67 @@
1
+ import { CacheStorage, TIDAuthToken, TIDUser } from '../../interfaces';
2
+ import { CacheKey } from './CacheKey';
3
+ export interface SessionStorageCacheOptions {
4
+ /**
5
+ * The cache key represents the keys for storing and retrieving user and token from auth
6
+ * @type {CacheKey}
7
+ */
8
+ cacheKey: CacheKey;
9
+ }
10
+ /**
11
+ * Class representing session storage caching
12
+ * NOTE: This type storage is cleared when the page session ends
13
+ */
14
+ export declare class SessionStorageCache implements CacheStorage {
15
+ /**
16
+ * Session storage from the browser
17
+ * @type {Storage}
18
+ */
19
+ private readonly sessionStorage;
20
+ /**
21
+ * The cache key represents the keys for storing and retrieving user and token from auth
22
+ * @type {CacheKey}
23
+ */
24
+ private readonly cacheKey;
25
+ /**
26
+ * Initialized configuration to store information into session storage
27
+ * @param {SessionStorageCacheOptions} options - Configuration for caching in session storage
28
+ */
29
+ constructor(options: SessionStorageCacheOptions);
30
+ /**
31
+ * Get token store in session storage
32
+ * @return {Promise<TIDAuthToken | undefined>} - Token store in session storage
33
+ */
34
+ getToken(): Promise<TIDAuthToken | undefined>;
35
+ /**
36
+ * Get user store in session storage
37
+ * @return {Promise<TIDUser | undefined>} - User store in session storage
38
+ */
39
+ getUser(): Promise<TIDUser | undefined>;
40
+ /**
41
+ * Store token in session storage
42
+ * @param {TIDAuthToken} authToken - Token that you want to store in session storage
43
+ * @return {Promise<void>} Empty promise
44
+ */
45
+ storeToken(authToken: TIDAuthToken): Promise<void>;
46
+ /**
47
+ * Store user in cache
48
+ * @param {TIDUser} user - User that you want to store in session storage
49
+ * @return {Promise<void>} Empty promise
50
+ */
51
+ storeUser(user: TIDUser): Promise<void>;
52
+ /**
53
+ * Get the full key from the cachekey for the user
54
+ * @return {string} - Full key to get the token from the session storage
55
+ */
56
+ getUserKey(): string;
57
+ /**
58
+ * Get the full key from the cachekey for the token
59
+ * @return {string} - Full key to get the token from the session storage
60
+ */
61
+ getAuthKey(): string;
62
+ /**
63
+ * The clear the cache from the session storage
64
+ * @return {Promise<void>} Empty promise
65
+ */
66
+ clear(): Promise<void>;
67
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Default value of the prefix key use it to store the token and the user
3
+ * @type {string}
4
+ */
5
+ export declare const PREFIX_KEY: string;
6
+ /**
7
+ * Default value of the suffix key use it to store the token
8
+ * @type {string}
9
+ */
10
+ export declare const AUTH_KEY: string;
11
+ /**
12
+ * Default value of the suffix key use it to store the user
13
+ * @type {string}
14
+ */
15
+ export declare const USER_KEY: string;
@@ -0,0 +1,48 @@
1
+ interface CookiesManagerOptions {
2
+ /**
3
+ * Client id of the application created in trimble developer console
4
+ * @type {string}
5
+ */
6
+ clientId: string;
7
+ }
8
+ interface CookieValue {
9
+ /**
10
+ * Code verifier used for the PKCE workflow
11
+ * @see {https://docs.trimblecloud.com/identity_v4.0/how-to/grant-flows/authorization-code-pkce/} Authorization Code with PKCE
12
+ * @type {string}
13
+ */
14
+ code_verifier: string;
15
+ }
16
+ /** Class to manage cookies */
17
+ export declare class CookiesManager {
18
+ /**
19
+ * Cookie full key to store and retrieve the information from cookies
20
+ * @type {string}
21
+ */
22
+ private readonly cookieKey;
23
+ /**
24
+ * Cookie storage. This object contain all functions necessary to retrieve and store tokens using cookies
25
+ * @type {CookiesStorage}
26
+ */
27
+ private readonly cookiesStorage;
28
+ /**
29
+ * Create a cookies manager to extract or save cookies in the browser
30
+ * @param {CookiesManagerOptions} options - Configuration for the managing the cookies
31
+ */
32
+ constructor(options: CookiesManagerOptions);
33
+ /**
34
+ * Store cookies in the browser
35
+ * @param {CookieValue} value - information to store
36
+ */
37
+ save(value: CookieValue): void;
38
+ /**
39
+ * Retrieve cookies in the browser
40
+ * @return {CookieValue | undefined} - Cookies from the browser
41
+ */
42
+ get(): CookieValue | undefined;
43
+ /**
44
+ * Clear information about the cookies stored in the browser
45
+ */
46
+ clear(): void;
47
+ }
48
+ export {};
@@ -0,0 +1,42 @@
1
+ interface CookiesOptions {
2
+ /**
3
+ * Number of days until the cookies expire
4
+ * @type {number}
5
+ */
6
+ expires?: number;
7
+ /**
8
+ * Domain name to registry the cookies for. By default, is the name of the site
9
+ * @type {string}
10
+ */
11
+ domain?: string;
12
+ }
13
+ /** Class to store cookies in the browser */
14
+ export declare class CookiesStorage {
15
+ /**
16
+ * Retrieve a cookie from the browser
17
+ * @param {string} key - Key to retrieve the cookies
18
+ */
19
+ get(key: string): any;
20
+ /**
21
+ * Store cookies in the browser
22
+ * @param {string} key - Key to save and retrieve the cookies
23
+ * @param {any} value - Information you want to store in cookies
24
+ * @param {CookiesOptions} options - Additional options you want to add to the cookies.
25
+ * @example Save cookies with one day of expiration
26
+ * cookiesStorage.set('key',{data:{...}},{expires:1})
27
+ * @example Save cookies with a custom domain
28
+ * cookiesStorage.set('key',{data:{...}},{domain:'https://example.com/subpath'})
29
+ */
30
+ set(key: string, value: any, options: CookiesOptions): void;
31
+ /**
32
+ * Remove a cookie from the browser
33
+ * @param {string} key - Key to remove the cookies from the browser
34
+ * @param {CookiesOptions} options - Additional options used when the cookie was declared
35
+ * @example Remove cookies without additional information
36
+ * cookiesStorage.remove('key')
37
+ * @example Remove cookies with custom domain
38
+ * cookiesStorage.remove('key',{domain:'https://example.com/subpath'})
39
+ */
40
+ remove(key: string, options?: CookiesOptions): void;
41
+ }
42
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Default value of the prefix key use it to store the cookies
3
+ * @type {string}
4
+ */
5
+ export declare const PREFIX_KEY: string;
@@ -0,0 +1,61 @@
1
+ import { TIDJWTUser, TIDUser } from './interfaces';
2
+ /**
3
+ * Remove the search params from the url
4
+ * @param {string} url - Url to remove the search params
5
+ * @return {string} - Url without the search params
6
+ * @example
7
+ * removeSearchParams('https://example.com/test?state=fake_state&another_prop=fake_prop')
8
+ * // will return https://example.com/test
9
+ * @example
10
+ * removeSearchParams('https://example.com/test')
11
+ * // will return https://example.com/test
12
+ * @example
13
+ * removeSearchParams('https://example.com/test?state=fake_state&another_prop=fake_prop#hash')
14
+ * // will return https://example.com/test
15
+ */
16
+ export declare const removeSearchParams: (url: string) => string;
17
+ /**
18
+ * Extract the params from the URL.
19
+ * @param {string} url - Url to extract information
20
+ * @return {string} - Params of the url
21
+ * @example
22
+ * getQueryParams('https://example.com/test?state=fake_state&another_prop=fake_prop')
23
+ * // will return ?state=fake_state&another_prop=fake_prop
24
+ */
25
+ export declare const getQueryParams: (url: string) => string;
26
+ /**
27
+ * Receives an url and converted into URLSearchParams
28
+ * @param {string} url - Url to extract information
29
+ * @return {URLSearchParams} - URLSearchParams containing the parameters from the URL
30
+ * @example Full url
31
+ * getSearchParams('https://example.com/test?state=fake_state&another_prop=fake_prop')
32
+ * @example Only params
33
+ * getSearchParams('?state=fake_state&another_prop=fake_prop')
34
+ */
35
+ export declare const getSearchParams: (url: string) => URLSearchParams;
36
+ /**
37
+ * Compare if the url contains the necessary information for the authentication
38
+ *
39
+ * Note: The required parameters that the url should contain are the following:
40
+ * * code
41
+ * * state
42
+ * * identity_provider
43
+ * @param redirectUrl - If the redirect url is provided, it will check if the url starts with the redirect url provided. If not, it will return false
44
+ * @param {string} url - Url to determined if it has the requirement auth params. By default, takes the url of the browser
45
+ * @return {boolean} - True or false if the url is valid
46
+ * @example No url
47
+ * hasAuthParams() // This will take the url from the browser
48
+ * @example Valid url
49
+ * getSearchParams('https://example.com/test?code=fake_code&state=fake_state')
50
+ * // return true
51
+ * @example Invalid url
52
+ * getSearchParams('https://example.com/test?code=fake_code')
53
+ * // return true
54
+ */
55
+ export declare const hasAuthParams: (url?: string, redirectUrl?: string) => boolean;
56
+ /**
57
+ * Converts the raw JWT user returned from TID and converted into a TIDUser
58
+ * @param {TIDJWTUser} jwtUser - TIDJWTUser to convert
59
+ * @return {TIDUser} - TIDJWTUser converted into a TIDUser
60
+ */
61
+ export declare const transformToTIDUser: (jwtUser: TIDJWTUser) => TIDUser;
@@ -0,0 +1,83 @@
1
+ import { TIDAuthState } from './state';
2
+ import { AuthState } from '../TIDClient';
3
+ export interface LoginWithRedirectOptions {
4
+ /**
5
+ * Function called when the user redirection is occurring
6
+ * If you send this function you will need to handle the redirection
7
+ * @param {string} url - Redirect url to TID with the necessary information to log in the user
8
+ */
9
+ onRedirect?: (url: string) => void;
10
+ }
11
+ export interface LogoutOptions {
12
+ /**
13
+ * Function called when the user redirection is occurring
14
+ * If you send this function you will need to handle the redirection
15
+ * @param {string} url - Redirect url to TID with the necessary information to log out the user
16
+ */
17
+ onRedirect?: (url: string) => void;
18
+ /**
19
+ * If you want to disable the auto redirect to TID after the logout is successful you can set this to true
20
+ * If you set this to true you will need to handle the redirection and the provider will clear the user information from the context
21
+ *
22
+ * **IMPORTANT**: If you set this to true the user information will be cleared from the context and isAuthenticated will be false
23
+ * if you are using the AuthenticationGuard component it will redirect the user to the login page automatically
24
+ * @default false
25
+ * @type {boolean}
26
+ * @example
27
+ * logout({disabledAutoRedirect: true})
28
+ */
29
+ disabledAutoRedirect?: boolean;
30
+ }
31
+ export interface TIDContextState extends TIDAuthState {
32
+ /**
33
+ * Authenticated the user using the url callback params,
34
+ * After the login is successful will load the user in TIDProvider context
35
+ * That way it can be access thought the whole react application
36
+ * @param {string} url - Custom configuration for teh redirection
37
+ * @return {Promise<AuthState>} Object contain the state returned from TID
38
+ * @throws {CodeVerifierNotFoundException} Will throw an exception if the session doesn't contain the code verifier
39
+ * @example No configuration
40
+ * handleCallback()
41
+ * // Will automatically take the url from the browser and try to log in the user
42
+ * @example Custom url
43
+ * handleCallback('https://example.com?code=code....')
44
+ * // Will try to log in the user with the url assign by the developer
45
+ */
46
+ handleCallback: (url?: string) => Promise<AuthState>;
47
+ /**
48
+ * Gets the access token from cache if the token already expired,
49
+ * will try to refresh it using the refresh token.
50
+ * In case that the user change it store the new user information in context
51
+ * @return {Promise<string>} Access token
52
+ * @throws {TokenNotFoundException} Will throw an exception there are not access token in cache
53
+ * @throws {TokenExpiredException} Will throw an if the user token expired
54
+ */
55
+ getAccessTokenSilently: () => Promise<string>;
56
+ /**
57
+ * Redirect the user to TID using the browser
58
+ * @param {LoginWithRedirectOptions} options - Custom configuration for teh redirection
59
+ * @return {Promise<void>} Empty promise
60
+ * @example No configuration
61
+ * loginWithRedirect()
62
+ * // Automatically redirects the user to TID with all necessary parameters
63
+ * @example Custom redirect
64
+ * loginWithRedirect({onRedirect: (url) => router.navigate(url)})
65
+ * // Redirect calls the onRedirect and pass through the url for TID redirection to the function
66
+ * // So it can be handled by the developer
67
+ */
68
+ loginWithRedirect: (options?: LoginWithRedirectOptions) => Promise<void>;
69
+ /**
70
+ * Redirect the user to TID using the browser
71
+ * @param {LogoutOptions} options - Custom configuration for teh redirection
72
+ * @return {Promise<void>} Empty promise
73
+ * @example No configuration
74
+ * logout()
75
+ * // Automatically redirects the user to TID to log out
76
+ * @example Custom redirect
77
+ * logout({onRedirect: (url) => router.navigate(url)})
78
+ * // Redirect calls the onRedirect and pass through the log-out url for TID to the function
79
+ * // So it can be handled by the developer
80
+ */
81
+ logout: (options?: LogoutOptions) => Promise<void>;
82
+ }
83
+ export declare const TIDContext: import("react").Context<TIDContextState | null>;
@@ -0,0 +1,90 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { TIDClient, PersistentStore, AuthState } from '../TIDClient';
3
+ export interface TIDProviderProps extends PropsWithChildren {
4
+ /**
5
+ * The URL for the Trimble Identity OpenID well known configuration endpoint
6
+ * Staging: https://stage.id.trimblecloud.com/.well-known/openid-configuration
7
+ * Production: https://id.trimble.com/.well-known/openid-configuration
8
+ * @type {string}
9
+ */
10
+ configurationEndpoint?: string;
11
+ /**
12
+ * Client id of the application created in trimble developer console
13
+ * @type {string}
14
+ */
15
+ clientId?: string;
16
+ /**
17
+ * The URL to which Trimble Identity should redirect after successfully authenticating a user
18
+ * @type {string}
19
+ */
20
+ redirectUrl?: string;
21
+ /**
22
+ * The URL to which Trimble Identity should redirect after successfully logout a user
23
+ * @type {string}
24
+ */
25
+ logoutRedirectUrl?: string;
26
+ /**
27
+ * The type of credentials you want (openID, or application_name)
28
+ * @type {string[]}
29
+ */
30
+ scopes?: string[];
31
+ /**
32
+ * Type persistent you want the user and token to be store
33
+ * in-memory - This one will only persist will the user stays in the page
34
+ * localStorage - This persistent doesn't have expiration date
35
+ * sessionStorage - This one is cleared when the page session ends
36
+ * @type {PersistentStore}
37
+ */
38
+ persistentStore?: PersistentStore;
39
+ /**
40
+ * TID client instance. You can send an instance of the TID Client
41
+ * if you want to handle the initialization yourself
42
+ * @type {TIDClient}
43
+ */
44
+ tidClient?: TIDClient;
45
+ /**
46
+ * When the redirect callback occur this function will be call once the user is login
47
+ * using the TIDClient.
48
+ * This could allow you to redirect the user into another page after the login happen
49
+ * @param {AuthState} authState - Object contain the state returned from TID
50
+ * @example Redirect the user into the dashboard page
51
+ * <TIDProvider onRedirectCallback={()=>{router.navigate('/dashboard')}}>
52
+ */
53
+ onRedirectCallback?: (authState: AuthState) => void;
54
+ /**
55
+ * When the redirect callback occur if this flag is set to true the TIDProvider will
56
+ * check if the redirect url match the current url, if it doesn't match it will not
57
+ * authenticate the user.
58
+ * If this flag is set to false the TIDProvider will just check if the url contain the
59
+ * auth params and will authenticate the user.
60
+ * @type {boolean}
61
+ *
62
+ * @example Flag set to true and the url doesn't match
63
+ * <TIDProvider checkRedirectUrlMatch={true}>
64
+ * // url: https://localhost:3000/dashboard
65
+ * This will not authenticate the user or try to handle the callback
66
+ *
67
+ * @example Flag set to true and the url match but doesn't contain the auth params
68
+ * <TIDProvider checkRedirectUrlMatch={true}>
69
+ * // url: https://localhost:3000/dashboard?state=123
70
+ * This will not authenticate the user or try to handle the callback
71
+ *
72
+ * @example Flag set to true and the url match and contain the auth params
73
+ * <TIDProvider checkRedirectUrlMatch={true}>
74
+ * // url: https://localhost:3000/dashboard?code=123&state=123
75
+ * This will authenticate the user and try to handle the callback
76
+ *
77
+ * @example Flag set to false
78
+ * <TIDProvider checkRedirectUrlMatch={false}>
79
+ * // url: https://localhost:3000/dashboard
80
+ * This will not authenticate the user because the url contain does contain the auth params
81
+ *
82
+ * @example Flag set to false
83
+ * <TIDProvider checkRedirectUrlMatch={false}>
84
+ * // url: https://localhost:3000/dashboard?code=123&state=123
85
+ * This will authenticate the user and try to handle the callback
86
+ */
87
+ checkRedirectUrlMatch?: boolean;
88
+ }
89
+ declare const TIDProvider: (props: TIDProviderProps) => React.JSX.Element;
90
+ export default TIDProvider;
@@ -0,0 +1,4 @@
1
+ export * from './TIDContext';
2
+ export declare const useAuth: () => import("./TIDContext").TIDContextState;
3
+ export declare const TIDProvider: (props: import("./TIDProvider").TIDProviderProps) => import("react").JSX.Element;
4
+ export type { TIDProviderProps } from './TIDProvider';
@@ -0,0 +1,28 @@
1
+ import { TIDAuthState } from './state';
2
+ import { TIDUser } from '../TIDClient';
3
+ /**
4
+ * Actions available to manage the state of the TID Provider
5
+ */
6
+ type Action = {
7
+ type: 'INIT';
8
+ user?: TIDUser;
9
+ } | {
10
+ type: 'LOGOUT';
11
+ } | {
12
+ type: 'GET_ACCESS_TOKEN_COMPLETE';
13
+ user?: TIDUser;
14
+ } | {
15
+ type: 'HANDLE_CALLBACK_COMPLETE';
16
+ user?: TIDUser;
17
+ } | {
18
+ type: 'ERROR';
19
+ error: Error;
20
+ };
21
+ /**
22
+ * This function manage the state and logic of the TID Provider
23
+ * @param {TIDAuthState} state - Current state of the application
24
+ * @param {Action} action - Action to execute
25
+ * @return {TIDAuthState} Empty promise
26
+ */
27
+ export declare const reducer: (state: TIDAuthState, action: Action) => TIDAuthState;
28
+ export {};
@@ -0,0 +1,26 @@
1
+ import { TIDUser } from '../TIDClient';
2
+ export interface TIDAuthState {
3
+ /**
4
+ * True or false if the user is authenticated
5
+ * @type {boolean}
6
+ */
7
+ isAuthenticated: boolean;
8
+ /**
9
+ * This property will indicate the developer that the TID Provider is still loading information from the cache
10
+ * By default, this state will be true, this will allow the developers to handle async functionality
11
+ * Note: This property will only be true the first time that the app executes
12
+ * @type {boolean}
13
+ */
14
+ isLoading: boolean;
15
+ /**
16
+ * Information of the user in session
17
+ * @type {TIDUser}
18
+ */
19
+ user?: TIDUser;
20
+ /**
21
+ * Property that let the developer know if an error happen during the authentication
22
+ * @type {Error}
23
+ */
24
+ error?: Error;
25
+ }
26
+ export declare const initialTIDAuthState: TIDAuthState;
@@ -0,0 +1,16 @@
1
+ import { TIDContextState } from './TIDContext';
2
+ /**
3
+ * This hook will allow you to access all functions and properties available in the TIDProvider
4
+ * Functions and properties available:
5
+ * * handleCallback
6
+ * * getAccessTokenSilently
7
+ * * loginWithRedirect
8
+ * * logout
9
+ * * isAuthenticated
10
+ * * isLoading
11
+ * * user
12
+ * * error
13
+ * @return {TIDContextState}
14
+ */
15
+ declare const useAuth: () => TIDContextState;
16
+ export default useAuth;
@@ -0,0 +1,4 @@
1
+ export { TIDClient } from './TIDClient';
2
+ export { TIDContext, useAuth, TIDProvider } from './TIDProvider';
3
+ export { AuthenticationGuard } from './AuthenticationGuard/AuthenticationGuard';
4
+ export type { PersistentStore } from './TIDClient';