Skip to content

Commit

Permalink
only show access request promoted notification quick action if user h…
Browse files Browse the repository at this point in the history
…asn't assumed access list yet (#51349)
  • Loading branch information
rudream authored Jan 22, 2025
1 parent 38a1bb3 commit 71de763
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web/packages/teleport/src/Login/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function useLogin() {

function onLogin(email, password, token) {
attemptActions.start();
storageService.clearLoginTime();
auth
.login(email, password, token)
.then(onSuccess)
Expand All @@ -109,6 +110,7 @@ export default function useLogin() {

function onLoginWithWebauthn(creds?: UserCredentials) {
attemptActions.start();
storageService.clearLoginTime();
auth
.loginWithWebauthn(creds)
.then(onSuccess)
Expand All @@ -119,6 +121,7 @@ export default function useLogin() {

function onLoginWithSso(provider: AuthProvider) {
attemptActions.start();
storageService.clearLoginTime();
const appStartRoute = getEntryRoute();
const ssoUri = cfg.getSsoUrl(provider.url, provider.name, appStartRoute);
history.push(ssoUri, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const Authenticated: React.FC<PropsWithChildren> = ({ children }) => {
if (result.requiresDeviceTrust === TrustedDeviceRequirement.REQUIRED) {
session.setDeviceTrustRequired();
}
storageService.setLoginTimeOnce();
setAttempt({ status: 'success' });
} catch (e) {
if (e instanceof ApiError && e.response?.status == 403) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ export const storageService = {
return time ? time : 0;
},

setLoginTimeOnce() {
const existingTime = window.localStorage.getItem(KeysEnum.LOGIN_TIME);
// Only set the login time if it doesn't already exist.
if (!existingTime) {
window.localStorage.setItem(KeysEnum.LOGIN_TIME, `${Date.now()}`);
}
},

getLoginTime(): Date {
const time = Number(window.localStorage.getItem(KeysEnum.LOGIN_TIME));
return time && !Number.isNaN(time) ? new Date(time) : new Date(0);
},

clearLoginTime() {
window.localStorage.removeItem(KeysEnum.LOGIN_TIME);
},

// setOnboardDiscover persists states used to determine if a user should
// be onboarded to use the discovery wizard or not. User should only
// be onboarded once upon login.
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/services/storageService/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const KeysEnum = {
'grv_users_not_equal_to_mau_acknowledged',
LOCAL_NOTIFICATION_STATES: 'grv_teleport_notification_states',
RECENT_HISTORY: 'grv_teleport_sidenav_recent_history',
LOGIN_TIME: 'grv_teleport_login_time',

// TODO(bl-nero): Remove once the new role editor is in acceptable state.
USE_NEW_ROLE_EDITOR: 'grv_teleport_use_new_role_editor',
Expand Down

0 comments on commit 71de763

Please sign in to comment.