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