mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
add url param token and skip login if provided
Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
@@ -44,6 +44,7 @@ import {
|
|||||||
import { translatedError } from "./TranslatedError";
|
import { translatedError } from "./TranslatedError";
|
||||||
import { useEventTarget } from "./useEvents";
|
import { useEventTarget } from "./useEvents";
|
||||||
import { Config } from "./config/Config";
|
import { Config } from "./config/Config";
|
||||||
|
import { useUrlParams } from "./UrlParams";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -152,7 +153,7 @@ interface Props {
|
|||||||
|
|
||||||
export const ClientProvider: FC<Props> = ({ children }) => {
|
export const ClientProvider: FC<Props> = ({ children }) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { token, userId, deviceId } = useUrlParams();
|
||||||
// null = signed out, undefined = loading
|
// null = signed out, undefined = loading
|
||||||
const [initClientState, setInitClientState] = useState<
|
const [initClientState, setInitClientState] = useState<
|
||||||
InitResult | null | undefined
|
InitResult | null | undefined
|
||||||
@@ -165,12 +166,20 @@ export const ClientProvider: FC<Props> = ({ children }) => {
|
|||||||
// the client.
|
// the client.
|
||||||
if (initializing.current) return;
|
if (initializing.current) return;
|
||||||
initializing.current = true;
|
initializing.current = true;
|
||||||
|
const tokenLogin =
|
||||||
|
!token && !userId
|
||||||
|
? undefined
|
||||||
|
: ({
|
||||||
|
token,
|
||||||
|
userId,
|
||||||
|
deviceId,
|
||||||
|
} as { token: string; userId: string });
|
||||||
|
|
||||||
loadClient()
|
loadClient(tokenLogin)
|
||||||
.then(setInitClientState)
|
.then(setInitClientState)
|
||||||
.catch((err) => logger.error(err))
|
.catch((err) => logger.error(err))
|
||||||
.finally(() => (initializing.current = false));
|
.finally(() => (initializing.current = false));
|
||||||
}, []);
|
}, [token, userId, deviceId]);
|
||||||
|
|
||||||
const changePassword = useCallback(
|
const changePassword = useCallback(
|
||||||
async (password: string) => {
|
async (password: string) => {
|
||||||
@@ -339,7 +348,11 @@ type InitResult = {
|
|||||||
passwordlessUser: boolean;
|
passwordlessUser: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function loadClient(): Promise<InitResult | null> {
|
async function loadClient(tokenLogin?: {
|
||||||
|
token: string;
|
||||||
|
userId: string;
|
||||||
|
deviceId: string;
|
||||||
|
}): Promise<InitResult | null> {
|
||||||
if (widget) {
|
if (widget) {
|
||||||
// We're inside a widget, so let's engage *matryoshka mode*
|
// We're inside a widget, so let's engage *matryoshka mode*
|
||||||
logger.log("Using a matryoshka client");
|
logger.log("Using a matryoshka client");
|
||||||
@@ -351,7 +364,15 @@ async function loadClient(): Promise<InitResult | null> {
|
|||||||
} else {
|
} else {
|
||||||
// We're running as a standalone application
|
// We're running as a standalone application
|
||||||
try {
|
try {
|
||||||
const session = loadSession();
|
let session = loadSession();
|
||||||
|
if (tokenLogin) {
|
||||||
|
session = {
|
||||||
|
user_id: tokenLogin.userId,
|
||||||
|
device_id: tokenLogin.deviceId, //"TOKEN_DEVICE",
|
||||||
|
access_token: tokenLogin.token,
|
||||||
|
passwordlessUser: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (!session) {
|
if (!session) {
|
||||||
logger.log("No session stored; continuing without a client");
|
logger.log("No session stored; continuing without a client");
|
||||||
return null;
|
return null;
|
||||||
@@ -371,7 +392,7 @@ async function loadClient(): Promise<InitResult | null> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const client = await initClient(initClientParams, true);
|
const client = await initClient(initClientParams, !tokenLogin);
|
||||||
return {
|
return {
|
||||||
client,
|
client,
|
||||||
passwordlessUser,
|
passwordlessUser,
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ interface UrlParams {
|
|||||||
* E2EE password
|
* E2EE password
|
||||||
*/
|
*/
|
||||||
password: string | null;
|
password: string | null;
|
||||||
|
/**
|
||||||
|
* Token for a user for instance login. This is used for bridge gosts.
|
||||||
|
*/
|
||||||
|
token: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is here as a stopgap, but what would be far nicer is a function that
|
// This is here as a stopgap, but what would be far nicer is a function that
|
||||||
@@ -200,6 +204,7 @@ export const getUrlParams = (
|
|||||||
fontScale: Number.isNaN(fontScale) ? null : fontScale,
|
fontScale: Number.isNaN(fontScale) ? null : fontScale,
|
||||||
analyticsID: parser.getParam("analyticsID"),
|
analyticsID: parser.getParam("analyticsID"),
|
||||||
allowIceFallback: parser.getFlagParam("allowIceFallback"),
|
allowIceFallback: parser.getFlagParam("allowIceFallback"),
|
||||||
|
token: parser.getParam("token"),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user