-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SDKConfig and SDKContext to core
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Config for FusionAuth Web SDKs | ||
*/ | ||
export type SDKConfig = { | ||
/** | ||
* The URL of the FusionAuth server. | ||
*/ | ||
serverUrl: string; | ||
|
||
/** | ||
* The client id of the application. | ||
*/ | ||
clientId: string; | ||
|
||
/** | ||
* The redirect URI of the application. | ||
*/ | ||
redirectUri: string; | ||
|
||
/** | ||
* The redirect URI for post-logout. Defaults the provided `redirectUri`. | ||
*/ | ||
postLogoutRedirectUri?: string; | ||
|
||
/** | ||
* Enables automatic token refreshing. Defaults to false. | ||
*/ | ||
shouldAutoRefresh?: boolean; | ||
|
||
/** | ||
* Enables the SDK to automatically handle fetching user info when logged in. Defaults to false. | ||
*/ | ||
shouldAutoFetchUserInfo?: boolean; | ||
|
||
/** | ||
* The number of seconds before the access token expiry when the auto refresh functionality kicks in if enabled. Default is 30. | ||
*/ | ||
autoRefreshSecondsBeforeExpiry?: number; | ||
|
||
/** | ||
* Callback function to be invoked with the `state` value upon redirect from login or register. | ||
*/ | ||
onRedirect?: (state?: string) => void; | ||
|
||
/** | ||
* The path to the login endpoint. | ||
*/ | ||
loginPath?: string; | ||
|
||
/** | ||
* The path to the register endpoint. | ||
*/ | ||
registerPath?: string; | ||
|
||
/** | ||
* The path to the logout endpoint. | ||
*/ | ||
logoutPath?: string; | ||
|
||
/** | ||
* The path to the token refresh endpoint. | ||
*/ | ||
tokenRefreshPath?: string; | ||
|
||
/** | ||
* The path to the me endpoint. | ||
*/ | ||
mePath?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SDKConfig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** The context provided by FusionAuth Web SDKs */ | ||
export type SDKContext = { | ||
/** | ||
* Whether the user is logged in. | ||
*/ | ||
isLoggedIn: boolean; | ||
|
||
/** | ||
* Data fetched from the 'me' endpoint. | ||
*/ | ||
userInfo?: UserInfo; | ||
|
||
/** | ||
* Fetches user info from the 'me' endpoint. | ||
* This is handled automatically if the SDK is configured with `shouldAutoFetchUserInfo`. | ||
* @returns {Promise<UserInfo>} | ||
*/ | ||
fetchUserInfo: () => Promise<UserInfo>; | ||
|
||
/** | ||
* Indicates that the fetchUserInfo call is unresolved. | ||
*/ | ||
isFetchingUserInfo: boolean; | ||
|
||
/** | ||
* Error occurred while fetching userInfo. | ||
*/ | ||
error?: Error; | ||
|
||
/** | ||
* Initiates login flow. | ||
* @param {string} [state] - Optional value to be echoed back to the SDK upon redirect. | ||
*/ | ||
startLogin: (state?: string) => void; | ||
|
||
/** | ||
* Initiates register flow. | ||
* @param {string} [state] - Optional value to be echoed back to the SDK upon redirect. | ||
*/ | ||
startRegister: (state?: string) => void; | ||
|
||
/** | ||
* Initiates logout flow. | ||
*/ | ||
startLogout: () => void; | ||
|
||
/** | ||
* Refreshes the access token a single time. | ||
* This is handled automatically if the SDK is configured with `shouldAutoRefresh`. | ||
*/ | ||
refreshToken: () => Promise<void>; | ||
|
||
/** | ||
* Initializes automatic access token refreshing. | ||
* This is handled automatically if the SDK is configured with `shouldAutoRefresh`. | ||
*/ | ||
initAutoRefresh: () => void; | ||
}; | ||
|
||
/** | ||
* User information returned from FusionAuth. | ||
*/ | ||
export type UserInfo = { | ||
applicationId?: string; | ||
email?: string; | ||
email_verified?: boolean; | ||
family_name?: string; | ||
given_name?: string; | ||
picture?: string; | ||
roles?: any[]; | ||
sid?: string; | ||
sub?: string; | ||
tid?: string; | ||
phone_number?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SDKContext'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './CookieHelpers'; | ||
export * from './SDKConfig'; | ||
export * from './SDKContext'; | ||
export * from './UrlHelpers'; | ||
export * from './TokenRefresher'; |