Login With Reapit
A singular component to enable auth with reapit
The login With Reapit button is a singular stand alone component which can be utilised in any project on it's own. The component is written with Svelte which compiles Vanilla JS, CSS and HTML so are framework agnostic and be used with any other front end tech of your choosing.

The Sign In With Reapit Button

The button leverages the Connect Session to handle the OAuth flow and returns a session object in a callback you provide.
Sign in With Reapit button
The Component is a single script provided by NPM package, you instantiate with a target div, your client credentials as per the browser API and pass in a callback to receive your session object. As per the NPM module, all caching, redirection and refreshing is taken care of by the package. When you have a session, the button will change function to be a logout which will clear your cache and end your session in Reapit Connect.

Agreeing to Permissions

When clicking the Sign In With Reapit button, a dialog window will appear with the following details
Agree to terms and permissions dialog

Yarn

Use the script tag below in your code base to use the ReapitConnectComponent.
1
yarn add @reapit/login-with-reapit
Copied!

NPM

Install the login-with-reapit package using npm.
1
npm i --save @reapit/login-with-reapit
Copied!
Below is an example of how to use the ReapitConnectComponent . In the connectHasSessionCallback function we fetch a list of appointments from the Platform API to demonstrate the full flow. The production connectUserPoolId is eu-west-2_eQ7dreNzJ.

Single HTML page example

1
<div id="reapit-connect-component"></div>
2
3
<script
4
type="text/javascript"
5
src="./node_modules/@reapit/login-with-reapit/public/dist/login-with-reapit.js"
6
></script>
7
8
<script>
9
const connectHasSessionCallback = (reapitConnectBrowserSession) => {
10
reapitConnectBrowserSession.connectSession().then(session => {
11
console.log('Session is', session)
12
fetch('https://platform.reapit.cloud/appointments', {
13
headers: {
14
'Content-Type': 'application/json',
15
'Authorization': `Bearer ${session.accessToken}`,
16
'api-version': '2020-01-31'
17
}
18
})
19
.then(res => res.json())
20
.then(appointments => console.log('Appointments are', appointments))
21
})
22
}
23
24
reapitConnectComponent && reapitConnectComponent({
25
connectClientId: '<<clientId here>>>',
26
connectUserPoolId: '<<userpool id here>>',
27
connectOAuthUrl: 'https://connect.reapit.cloud',
28
connectLoginRedirectPath: '',
29
connectLogoutRedirectPath: '/login',
30
rootElement: '#reapit-connect-component',
31
connectHasSessionCallback,
32
companyName: 'My Company',
33
})
34
</script>
Copied!

ES6+ example

1
import { reapitConnectComponent } from '@reapit/login-with-reapit'
2
3
4
const connectHasSessionCallback = (reapitConnectBrowserSession) => {
5
reapitConnectBrowserSession.connectSession().then(session => {
6
console.log('Session is', session)
7
fetch('https://platform.reapit.cloud/appointments', {
8
headers: {
9
'Content-Type': 'application/json',
10
'Authorization': `Bearer ${session.accessToken}`,
11
'api-version': '2020-01-31'
12
}
13
})
14
.then(res => res.json())
15
.then(appointments => console.log('Appointments are', appointments))
16
})
17
}
18
19
reapitConnectComponent && reapitConnectComponent({
20
connectClientId: '<<clientId here>>>',
21
connectUserPoolId: '<<userpool id here>>',
22
connectOAuthUrl: 'https://connect.reapit.cloud',
23
connectLoginRedirectPath: '',
24
connectLogoutRedirectPath: '/login',
25
rootElement: '#reapit-connect-component',
26
connectHasSessionCallback,
27
companyName: 'My Company',
28
})
Copied!

rootElement

The rootElement property can be passed either query string, DOM element or shadow DOM element.
1
reapitConnectComponent && reapitConnectComponent({
2
connectClientId: '<<clientId here>>>',
3
connectUserPoolId: '<<userpool id here>>',
4
connectOAuthUrl: 'https://connect.reapit.cloud',
5
connectLoginRedirectPath: '',
6
connectLogoutRedirectPath: '/login',
7
rootElement: document.getElementById('reapit-connect-component'),
8
connectHasSessionCallback,
9
companyName: 'My Company',
10
})
Copied!
Last modified 1mo ago