You've already forked matrix-react-sdk
							
							
				mirror of
				https://github.com/matrix-org/matrix-react-sdk.git
				synced 2025-11-04 11:51:45 +03:00 
			
		
		
		
	Add utility method mxLoginWithAccessToken to login with existing access token (#7261)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							b69ad0cd0b
						
					
				
				
					commit
					aa7cae08aa
				
			
							
								
								
									
										1
									
								
								src/@types/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								src/@types/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -100,6 +100,7 @@ declare global {
 | 
			
		||||
        mxOnRecaptchaLoaded?: () => void;
 | 
			
		||||
        electron?: Electron;
 | 
			
		||||
        mxSendSentryReport: (userText: string, issueUrl: string, error: Error) => Promise<void>;
 | 
			
		||||
        mxLoginWithAccessToken: (hsUrl: string, accessToken: string) => Promise<void>;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    interface DesktopCapturerSource {
 | 
			
		||||
 
 | 
			
		||||
@@ -538,8 +538,8 @@ export function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixC
 | 
			
		||||
 * fires on_logging_in, optionally clears localstorage, persists new credentials
 | 
			
		||||
 * to localstorage, starts the new client.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {MatrixClientCreds} credentials
 | 
			
		||||
 * @param {Boolean} clearStorage
 | 
			
		||||
 * @param {IMatrixClientCreds} credentials
 | 
			
		||||
 * @param {Boolean} clearStorageEnabled
 | 
			
		||||
 *
 | 
			
		||||
 * @returns {Promise} promise which resolves to the new MatrixClient once it has been started
 | 
			
		||||
 */
 | 
			
		||||
@@ -918,3 +918,17 @@ export function stopMatrixClient(unsetClient = true): void {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Utility method to perform a login with an existing access_token
 | 
			
		||||
window.mxLoginWithAccessToken = async (hsUrl: string, accessToken: string): Promise<void> => {
 | 
			
		||||
    const tempClient = createClient({
 | 
			
		||||
        baseUrl: hsUrl,
 | 
			
		||||
        accessToken,
 | 
			
		||||
    });
 | 
			
		||||
    const { user_id: userId } = await tempClient.whoami();
 | 
			
		||||
    await doSetLoggedIn({
 | 
			
		||||
        homeserverUrl: hsUrl,
 | 
			
		||||
        accessToken,
 | 
			
		||||
        userId,
 | 
			
		||||
    }, true);
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
 | 
			
		||||
 | 
			
		||||
export interface IMatrixClientCreds {
 | 
			
		||||
    homeserverUrl: string;
 | 
			
		||||
    identityServerUrl: string;
 | 
			
		||||
    identityServerUrl?: string;
 | 
			
		||||
    userId: string;
 | 
			
		||||
    deviceId?: string;
 | 
			
		||||
    accessToken: string;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user