@micha.bigler/ui-core-micha 2.1.16 → 2.1.18
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/dist/auth/AuthContext.js +34 -16
- package/dist/auth/authApi.js +19 -0
- package/dist/components/AccessCodeManager.js +8 -2
- package/dist/components/BulkInviteCsvTab.js +7 -1
- package/dist/components/LoginForm.js +2 -2
- package/dist/components/ProfileComponent.js +65 -5
- package/dist/components/SecurityComponent.js +23 -6
- package/dist/components/SocialLoginButtons.js +7 -4
- package/dist/components/UserInviteComponent.js +8 -2
- package/dist/components/UserListComponent.js +163 -21
- package/dist/i18n/authTranslations.js +30 -0
- package/dist/pages/AccountPage.js +11 -22
- package/dist/pages/LoginPage.js +16 -2
- package/dist/utils/authService.js +41 -2
- package/package.json +2 -1
- package/src/auth/AuthContext.jsx +64 -16
- package/src/auth/authApi.jsx +22 -1
- package/src/components/AccessCodeManager.jsx +14 -4
- package/src/components/BulkInviteCsvTab.jsx +9 -3
- package/src/components/LoginForm.jsx +58 -48
- package/src/components/ProfileComponent.jsx +117 -4
- package/src/components/SecurityComponent.jsx +58 -28
- package/src/components/SocialLoginButtons.jsx +57 -49
- package/src/components/UserInviteComponent.jsx +11 -4
- package/src/components/UserListComponent.jsx +252 -40
- package/src/i18n/authTranslations.ts +31 -1
- package/src/pages/AccountPage.jsx +34 -39
- package/src/pages/LoginPage.jsx +25 -6
- package/src/utils/authService.js +51 -3
package/src/utils/authService.js
CHANGED
|
@@ -135,12 +135,60 @@ export async function authenticateMfaWithPasskey() {
|
|
|
135
135
|
return authenticateWithMFA({ credential: credentialJson });
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
function getCsrfTokenFromCookie() {
|
|
139
|
+
if (typeof document === 'undefined' || !document.cookie) return null;
|
|
140
|
+
const match = document.cookie.match(/(?:^|; )csrftoken=([^;]+)/);
|
|
141
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function submitSocialRedirectForm({ provider, callbackUrl, csrfToken }) {
|
|
145
|
+
const form = document.createElement('form');
|
|
146
|
+
form.method = 'POST';
|
|
147
|
+
form.action = `${HEADLESS_BASE}/auth/provider/redirect`;
|
|
148
|
+
form.style.display = 'none';
|
|
149
|
+
|
|
150
|
+
const fields = {
|
|
151
|
+
provider,
|
|
152
|
+
process: 'login',
|
|
153
|
+
callback_url: callbackUrl,
|
|
154
|
+
csrfmiddlewaretoken: csrfToken,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
Object.entries(fields).forEach(([name, value]) => {
|
|
158
|
+
const input = document.createElement('input');
|
|
159
|
+
input.type = 'hidden';
|
|
160
|
+
input.name = name;
|
|
161
|
+
input.value = String(value);
|
|
162
|
+
form.appendChild(input);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
document.body.appendChild(form);
|
|
166
|
+
form.submit();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function startSocialLogin(provider) {
|
|
139
170
|
if (typeof window === 'undefined') {
|
|
140
171
|
throw normaliseApiError(
|
|
141
172
|
new Error('Auth.SOCIAL_LOGIN_NOT_IN_BROWSER'),
|
|
142
173
|
'Auth.SOCIAL_LOGIN_NOT_IN_BROWSER'
|
|
143
174
|
);
|
|
144
175
|
}
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
// Ensures csrftoken cookie exists before form POST.
|
|
179
|
+
await apiClient.get('/api/csrf/');
|
|
180
|
+
} catch {
|
|
181
|
+
// Continue; token might already be present.
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const csrfToken = getCsrfTokenFromCookie();
|
|
185
|
+
if (!csrfToken) {
|
|
186
|
+
throw normaliseApiError(
|
|
187
|
+
new Error('Auth.SOCIAL_LOGIN_FAILED'),
|
|
188
|
+
'Auth.SOCIAL_LOGIN_FAILED',
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const callbackUrl = `${window.location.origin}/login`;
|
|
193
|
+
submitSocialRedirectForm({ provider, callbackUrl, csrfToken });
|
|
194
|
+
}
|