go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/web/rpcexplorer/src/components/login_state.tsx (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import Avatar from '@mui/material/Avatar'; 16 import Button from '@mui/material/Button'; 17 import Divider from '@mui/material/Divider'; 18 import Typography from '@mui/material/Typography'; 19 20 import { useGlobals } from '../context/globals'; 21 22 // Shows Login/Logout buttons and the account info. 23 // 24 // If login sessions are not supported, just renders nothing. 25 export const LoginState = () => { 26 const { tokenClient } = useGlobals(); 27 28 // When using stateless auth, there's no login/logout at all. 29 if (tokenClient.sessionState == 'stateless') { 30 return <></>; 31 } 32 33 // If logged out, show the login button. Note that it does regular browser 34 // navigation resulting in the page reload: no need to hook up anything to it. 35 if (tokenClient.sessionState == 'loggedout') { 36 return <Button color="inherit" href={tokenClient.loginUrl}>Login</Button>; 37 } 38 39 // Otherwise show the account state and the logout button. 40 const account = tokenClient.sessionState; 41 return ( 42 <> 43 { 44 account.picture && <Avatar alt={account.email} src={account.picture} /> 45 } 46 <Typography sx={{ pl: 1 }}>{account.email}</Typography> 47 <Divider 48 orientation='vertical' 49 variant='middle' 50 flexItem 51 sx={{ pl: 1, borderColor: '#ffffff40' }} 52 /> 53 <Button color="inherit" href={tokenClient.logoutUrl}>Logout</Button> 54 </> 55 ); 56 };