@myxtra/authentication-green 2.0.0 → 2.1.0
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 +79 -0
- package/dist/{App-af44a4a3.mjs → App-b8d0f682.mjs} +306 -301
- package/dist/index-c468a93b.mjs +9006 -0
- package/dist/xtra-authentication.mjs +2 -2
- package/package.json +6 -6
- package/dist/index-ae7de489.mjs +0 -8992
package/README.md
CHANGED
|
@@ -116,5 +116,84 @@ type Config = {
|
|
|
116
116
|
redirectUrl?: string;
|
|
117
117
|
// The position of the flyout menu, defaults to 'right'
|
|
118
118
|
position?: 'left' | 'right';
|
|
119
|
+
// The ID of the commerce/BOU for which the component will show the icon when the Terms & Condition dialog is shown.
|
|
120
|
+
commerceId?:
|
|
121
|
+
| 'bioplanet'
|
|
122
|
+
| 'collectgo'
|
|
123
|
+
| 'collibri'
|
|
124
|
+
| 'colruyt'
|
|
125
|
+
| 'colruytacademy'
|
|
126
|
+
| 'colruytgroup'
|
|
127
|
+
| 'dats24'
|
|
128
|
+
| 'dreambaby'
|
|
129
|
+
| 'dreamland'
|
|
130
|
+
| 'okay'
|
|
131
|
+
| 'spar'
|
|
132
|
+
| 'xtra';
|
|
119
133
|
};
|
|
120
134
|
```
|
|
135
|
+
|
|
136
|
+
## Events & window object
|
|
137
|
+
|
|
138
|
+
The authentication component will emit events and add properties to the window object. For backwards
|
|
139
|
+
compatibility with the orange toolkit, the window properties are the same.
|
|
140
|
+
|
|
141
|
+
### Window object
|
|
142
|
+
|
|
143
|
+
Everything is available under the `window.xtra` object. If the user is authenticated, the component
|
|
144
|
+
will also add the following properties to the window object:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
type XTRA = {
|
|
148
|
+
user: {
|
|
149
|
+
firstName: () => string;
|
|
150
|
+
lastName: () => string;
|
|
151
|
+
dob: () => number;
|
|
152
|
+
mob: () => number;
|
|
153
|
+
yob: () => number;
|
|
154
|
+
gender: () => 'M' | 'F';
|
|
155
|
+
phone: () => string;
|
|
156
|
+
streetName: () => string,
|
|
157
|
+
houseNr: () => string,
|
|
158
|
+
box: () => string,
|
|
159
|
+
zip: () => string,
|
|
160
|
+
city: () => string,
|
|
161
|
+
country: () => string,
|
|
162
|
+
email: () => string,
|
|
163
|
+
cbh: () => string,
|
|
164
|
+
state: () => 'Authenticated',
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The authenticated event is sent through
|
|
169
|
+
[window.postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage), below you
|
|
170
|
+
can find an example of how to listen for the event:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
type XtraAuthenticationMessageEventData = {
|
|
174
|
+
source: 'xtra-authentication';
|
|
175
|
+
isAuthenticated?: boolean;
|
|
176
|
+
address?: Address;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const onMessage = (message: MessageEvent<XtraAuthenticationMessageEventData>) => {
|
|
180
|
+
// Ensure the event wasn't sent from another domain
|
|
181
|
+
if (event.origin !== new URL(window.location.href).origin) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Ensure the event wasn't sent from another source
|
|
186
|
+
if (!event.data.source === 'xtra-authenticaiton') {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!event.data.isAuthenticated) {
|
|
191
|
+
// TODO: add logic in case the user is not authenticated
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// TODO: add logic when the user is authenticated (window.xtra is set here)
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
window.addEventListener('message', onMessage);
|
|
199
|
+
```
|