feat(auth): include existing device ID in SSO and password login flows
This commit is contained in:
@@ -14,8 +14,10 @@ export function SSOLogin({ providers, redirectUrl, action, saveScreenSpace }: SS
|
||||
const baseUrl = discovery['m.homeserver'].base_url;
|
||||
const mx = useMemo(() => createClient({ baseUrl }), [baseUrl]);
|
||||
|
||||
const getSSOIdUrl = (ssoId?: string): string =>
|
||||
mx.getSsoLoginUrl(redirectUrl, 'sso', ssoId, action);
|
||||
const getSSOIdUrl = (ssoId?: string): string => {
|
||||
const existingDeviceId = localStorage.getItem('cinny_device_id') ?? undefined;
|
||||
return mx.getSsoLoginUrl(redirectUrl, 'sso', ssoId, action, existingDeviceId);
|
||||
};
|
||||
|
||||
const withoutIcon = providers
|
||||
? providers.find(
|
||||
|
||||
@@ -126,6 +126,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
useLoginComplete(loginState.status === AsyncStatus.Success ? loginState.data : undefined);
|
||||
|
||||
const handleUsernameLogin = (username: string, password: string) => {
|
||||
const existingDeviceId = localStorage.getItem('cinny_device_id') ?? undefined;
|
||||
startLogin(baseUrl, {
|
||||
type: 'm.login.password',
|
||||
identifier: {
|
||||
@@ -133,6 +134,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
user: username,
|
||||
},
|
||||
password,
|
||||
device_id: existingDeviceId,
|
||||
initial_device_display_name: 'Paarrot',
|
||||
});
|
||||
};
|
||||
@@ -144,6 +146,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
|
||||
const getBaseUrl = factoryGetBaseUrl(clientConfig, mxIdServer);
|
||||
|
||||
const existingDeviceId = localStorage.getItem('cinny_device_id') ?? undefined;
|
||||
startLogin(getBaseUrl, {
|
||||
type: 'm.login.password',
|
||||
identifier: {
|
||||
@@ -151,10 +154,12 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
user: mxIdUsername,
|
||||
},
|
||||
password,
|
||||
device_id: existingDeviceId,
|
||||
initial_device_display_name: 'Paarrot',
|
||||
});
|
||||
};
|
||||
const handleEmailLogin = (email: string, password: string) => {
|
||||
const existingDeviceId = localStorage.getItem('cinny_device_id') ?? undefined;
|
||||
startLogin(baseUrl, {
|
||||
type: 'm.login.password',
|
||||
identifier: {
|
||||
@@ -163,6 +168,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
address: email,
|
||||
},
|
||||
password,
|
||||
device_id: existingDeviceId,
|
||||
initial_device_display_name: 'Paarrot',
|
||||
});
|
||||
};
|
||||
|
||||
@@ -54,9 +54,11 @@ export function TokenLogin({ token }: TokenLoginProps) {
|
||||
>(useCallback(login, []));
|
||||
|
||||
useEffect(() => {
|
||||
const existingDeviceId = localStorage.getItem('cinny_device_id') ?? undefined;
|
||||
startLogin(baseUrl, {
|
||||
type: 'm.login.token',
|
||||
token,
|
||||
device_id: existingDeviceId,
|
||||
initial_device_display_name: 'Paarrot',
|
||||
});
|
||||
}, [baseUrl, token, startLogin]);
|
||||
|
||||
Reference in New Issue
Block a user