Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web) - UI for revoking auth tokens, active and inactive token lists #5253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wendybujalski
Copy link
Contributor

Screenshot 2025-01-14 at 6 01 07 PM

Copy link

github-actions bot commented Jan 14, 2025

Dependency Review

✅ No vulnerabilities or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@wendybujalski wendybujalski requested a review from stack72 January 14, 2025 23:03
@wendybujalski wendybujalski force-pushed the wendy/eng-2901-see-expired-and-revoked-api-tokens branch from ff7b7ec to 7deb5b9 Compare January 14, 2025 23:07
@@ -1,6 +1,6 @@
<template>
<tr
class="children:px-md children:py-sm children:truncate text-sm font-medium text-gray-800 dark:text-gray-200"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frontend Best Practices:

Only use the approved abstract colors - shade, neutral, action, success, warning, and destructive. Do not use named Tailwind colors like red or gray.

@wendybujalski wendybujalski force-pushed the wendy/eng-2901-see-expired-and-revoked-api-tokens branch from 6dd0797 to d665330 Compare January 14, 2025 23:28
@wendybujalski wendybujalski requested a review from jkeiser January 14, 2025 23:35

// This pokes the computed values to check if any tokens have expired every 5 seconds
const EXPIRATION_CHECK_INTERVAL = 5000;
const checkExpiration = ref();
Copy link
Contributor

@jkeiser jkeiser Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkExpiration doesn't need to be a ref, seems like.

Ooh, if you set a now variable instead of a tick counter, it gets rid of the need for a bunch of code as well as for the warning itself:

const now = ref(Date.now())
const expired = computed(() => expiresAt.value?.getTime() <= now.value);

let checkExpiration;
onMounted(() => {
  checkExpiration = setInterval(() => {
    now.value = Date.now()
  }, EXPIRATION_CHECK_INTERVAL);
}
onUnmounted(() => clearInterval(checkExpiration));

The current code works fine though, but probably needs a comment in the spot where you ignore the warning.

@wendybujalski wendybujalski added this pull request to the merge queue Jan 14, 2025
const listedTokens = computed(() =>
_.reverse(_.sortBy(_.values(authTokens.state.value), "createdAt")),
);
// This pokes the computed values to check if any tokens have expired every 5 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the thing to do here is have this be the only recomputer. Instead of storing simple AuthToken, we could store AuthToken & { isExpired: boolean }. Then we update isExpired to true whenever we notice a token becomes expired.

That way, the listedTokens / activeTokens split can just use token.isExpired || token.revokedAt and the AuthTokenListItem would automatically get isExpired passed in as well (and could drive itself off of that instead of running its own loop).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds like a much simpler system - I can make those changes in my next PR 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or fold them into this one now!)

Copy link
Contributor

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

I think we might be able to streamline the expiration timer stuff a bit (down to one loop, and make it set now so the computation is straightforward) but we can mull that over tomorrow.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 15, 2025
@@ -92,8 +92,16 @@ router.put("/workspaces/:workspaceId/authTokens/:authTokenId", async (ctx) => {
ctx.body = { authToken };
});

// revoke the given authToken for the given workspace
router.post("/workspaces/:workspaceId/authTokens/:authTokenId/revoke", async (ctx) => {
const { authToken } = await authorizeAuthTokenRoute(ctx, RoleType.OWNER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be [RoleType.OWNER]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants