Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/admin/users/impersonate.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert } from "antd";6import { join } from "path";78import { Rendered, useEffect, useState } from "@cocalc/frontend/app-framework";9import { Loading } from "@cocalc/frontend/components";10import { appBasePath } from "@cocalc/frontend/customize/app-base-path";11import { webapp_client } from "@cocalc/frontend/webapp-client";1213interface Props {14account_id: string;15first_name: string;16last_name: string;17}1819export function Impersonate(props: Readonly<Props>) {20const { first_name, last_name, account_id } = props;2122const [auth_token, set_auth_token] = useState<string | null>(null);23const [err, set_err] = useState<string | null>(null);2425async function get_token(): Promise<void> {26try {27const auth_token = await webapp_client.admin_client.get_user_auth_token(28account_id,29);30set_auth_token(auth_token);31set_err(null);32} catch (err) {33set_err(err.toString());34set_auth_token(null);35}36}3738useEffect(() => {39get_token();40}, []);4142function render_link(): Rendered {43if (auth_token == null) {44return <Loading />;45}46// lang_temp: https://github.com/sagemathinc/cocalc/issues/778247const link = join(appBasePath, `auth/impersonate?auth_token=${auth_token}&lang_temp=en`);48return (49<div>50<a href={link} target="_blank" rel="noopener noreferrer">51Right click and open this link in a new incognito window, where you52will be signed in as {first_name} {last_name}...53</a>54<br />55The actual link:56<pre style={{ fontSize: "11pt", textAlign: "center" }}>57<a href={link} target="_blank" rel="noopener noreferrer">58{link}59</a>60</pre>61</div>62);63}6465function render_err(): Rendered {66if (err != null) {67return (68<div>69<b>ERROR</b> {err}70</div>71);72}73}7475return (76<Alert77type="warning"78style={{ margin: "15px" }}79message={80<b>81Impersonate user "{first_name} {last_name}"82</b>83}84description={85<>86{render_err()}87{render_link()}88</>89}90/>91);92}939495