@sesamy/sesamy-js 1.12.1 → 1.13.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.
- package/README.md +129 -0
- package/dist/sesamy-js.cjs +5 -5
- package/dist/sesamy-js.d.ts +18 -6
- package/dist/sesamy-js.iife.js +5 -5
- package/dist/sesamy-js.mjs +1512 -1493
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ The following methods are available on the `sesamy` object:
|
|
|
61
61
|
- autoOnboard: trigger the auto-onboarding process for a product by sku
|
|
62
62
|
- getVersion: returns the version of the sesamy-js library
|
|
63
63
|
- getPaymentIssues: returns a list of failed payments and cards that will expire
|
|
64
|
+
- generateLink: creates a link to a sesamy hosted service such as account or consume. If the user is authenticated, the link will be signed so that the user can access the service without logging in again.
|
|
64
65
|
- clearCache: clears the cache for the sesamy-js library
|
|
65
66
|
|
|
66
67
|
## Events
|
|
@@ -119,3 +120,131 @@ These are the available configuration options, with their default values:
|
|
|
119
120
|
},
|
|
120
121
|
}
|
|
121
122
|
```
|
|
123
|
+
|
|
124
|
+
# Auth API
|
|
125
|
+
|
|
126
|
+
## `isAuthenticated()`
|
|
127
|
+
|
|
128
|
+
Checks if the user is currently authenticated. This function verifies the existence of a valid session by checking both the local storage for an access token and the state of the Auth0 client.
|
|
129
|
+
|
|
130
|
+
### Returns
|
|
131
|
+
|
|
132
|
+
- **boolean**: Returns `true` if the user is authenticated either via local storage tokens or the Auth0 client; otherwise, it returns `false`.
|
|
133
|
+
|
|
134
|
+
### Example
|
|
135
|
+
|
|
136
|
+
The following example demonstrates how to check if a user is currently authenticated:
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { isAuthenticated } from '@sesamy/sesamy-js';
|
|
140
|
+
|
|
141
|
+
isAuthenticated()
|
|
142
|
+
.then(isAuth => {
|
|
143
|
+
if (isAuth) {
|
|
144
|
+
console.log('User is authenticated.');
|
|
145
|
+
} else {
|
|
146
|
+
console.log('User is not authenticated.');
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
.catch(error => {
|
|
150
|
+
console.error('Error checking authentication status:', error);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## `loginWithRedirect(options?: LoginWithRedirectOptions)`
|
|
155
|
+
|
|
156
|
+
Initiates a login flow that redirects the user to an Auth0 hosted login page. Once the user authenticates, they will be redirected back to the specified `redirect_uri` within your application.
|
|
157
|
+
|
|
158
|
+
### Parameters
|
|
159
|
+
|
|
160
|
+
- `options` (optional): An object containing customization options for the login flow.
|
|
161
|
+
- `appState`: (optional, object) Used to store state before doing the redirect.
|
|
162
|
+
- `authorizationParams`: (optional, object) Additional parameters to include in the authorization request.
|
|
163
|
+
- `audience`: (optional, string) The audience to request access to.
|
|
164
|
+
- `scope`: (optional, string) The scope of the access request.
|
|
165
|
+
- `login_hint`: (optional, string) A hint to pre-fill the username on the login page.
|
|
166
|
+
- `organization`: (optional, string) The organization to authenticate with.
|
|
167
|
+
- `redirect_uri`: (optional, string) The URL to redirect the user to after login.
|
|
168
|
+
|
|
169
|
+
### Returns
|
|
170
|
+
|
|
171
|
+
This function returns a `Promise` that resolves when the redirect is successfully initiated.
|
|
172
|
+
|
|
173
|
+
### Example
|
|
174
|
+
|
|
175
|
+
The following example demonstrates how to use `loginWithRedirect` to initiate a login flow with an email address pre-filled:
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
import { loginWithRedirect } from '@sesamy/sesamy-js';
|
|
179
|
+
|
|
180
|
+
// Optionally pass the user's email to pre-fill on the login form
|
|
181
|
+
const loginOptions = {
|
|
182
|
+
authorizationParams: {
|
|
183
|
+
login_hint: 'user@example.com',
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Redirect the user to the login page
|
|
188
|
+
loginWithRedirect(loginOptions);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## `logout(options?: LogoutOptions)`
|
|
192
|
+
|
|
193
|
+
Terminates the user's session and optionally redirects the user to a specified URL after logout. This function clears any local session tokens and interacts with the Auth0 API to end the session.
|
|
194
|
+
|
|
195
|
+
### Parameters
|
|
196
|
+
|
|
197
|
+
- `options` (optional): An object containing customization options for the logout process.
|
|
198
|
+
- `returnTo`: (optional, string) The URL to redirect users to after logging out. Defaults to the current page URL if not provided.
|
|
199
|
+
|
|
200
|
+
### Returns
|
|
201
|
+
|
|
202
|
+
This function does not return a value. It causes a redirect to the specified `returnTo` URL or performs a page refresh if no URL is provided.
|
|
203
|
+
|
|
204
|
+
### Example
|
|
205
|
+
|
|
206
|
+
The following example demonstrates how to log out a user and redirect them to the homepage:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
import { logout } from '@sesamy/sesamy-js';
|
|
210
|
+
|
|
211
|
+
// Specify the URL to redirect to after logout
|
|
212
|
+
const logoutOptions = {
|
|
213
|
+
returnTo: 'https://www.yourdomain.com',
|
|
214
|
+
};
|
|
215
|
+
// Redirects the user to the auth server to log out
|
|
216
|
+
logout(logoutOptions);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## `setToken(accessToken: string, expiresIn?: number)`
|
|
220
|
+
|
|
221
|
+
Stores the provided access token in local storage and optionally sets an expiration time for it. Additionally, this function parses the access token to extract user information and triggers an authentication event.
|
|
222
|
+
|
|
223
|
+
### Parameters
|
|
224
|
+
|
|
225
|
+
- `accessToken` (string): The access token to store and use for session management.
|
|
226
|
+
- `expiresIn` (optional, number): The time in seconds from now when the token should expire.
|
|
227
|
+
|
|
228
|
+
### Returns
|
|
229
|
+
|
|
230
|
+
This function does not return a value but triggers an event indicating that a user has been authenticated with the new token.
|
|
231
|
+
|
|
232
|
+
### Example
|
|
233
|
+
|
|
234
|
+
The following example demonstrates how to store an access token and set an expiration time:
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
import { setToken } from '@sesamy/sesamy-js';
|
|
238
|
+
|
|
239
|
+
// Example access token and expiration period
|
|
240
|
+
const accessToken = 'your.access.token';
|
|
241
|
+
const expiresIn = 3600; // 1 hour in seconds
|
|
242
|
+
|
|
243
|
+
setToken(accessToken, expiresIn)
|
|
244
|
+
.then(() => {
|
|
245
|
+
console.log('Token set successfully and user authenticated.');
|
|
246
|
+
})
|
|
247
|
+
.catch(error => {
|
|
248
|
+
console.error('Failed to set token:', error);
|
|
249
|
+
});
|
|
250
|
+
```
|