Skip to content

Commit

Permalink
fix: Token expiry
Browse files Browse the repository at this point in the history
Closes #35 by correctly calculating token expiry time.
Also, move warning below the button so the button doesn't move.
  • Loading branch information
mjaquiery committed Oct 29, 2024
1 parent 473adac commit 4a24b08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "galv-client",
"version": "2.3.0",
"version": "2.3.1",
"private": true,
"proxy": "http://app/",
"type": "module",
Expand Down
20 changes: 10 additions & 10 deletions src/Components/ResourceCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export function TokenCreator({
},
})

const update_ttl = (v: number | undefined) => {
const x = (v ?? 0) * timeUnit
x > 0 ? setTTL(x) : setTTL(undefined)
const getTTL = () => {
const x = (ttl ?? 0) * timeUnit
return x > 0 ? x : undefined
}

const time_units = {
Expand Down Expand Up @@ -139,7 +139,7 @@ export function TokenCreator({
step={1}
min={0}
value={ttl || 0}
onChange={(_e, v) => update_ttl(v ?? 0)}
onChange={(_e, v) => setTTL(v ?? 0)}
/>
<Select
labelId="select-time-unit-label"
Expand All @@ -155,21 +155,21 @@ export function TokenCreator({
))}
</Select>
</Stack>
{!ttl && (
<Alert severity="info">
Tokens with no TTL value will be valid forever.
</Alert>
)}
<Button
variant="contained"
color="success"
onClick={() =>
create_mutation.mutate({ name, ttl: ttl || undefined })
create_mutation.mutate({ name, ttl: getTTL() })
}
disabled={name === ''}
>
Create
</Button>
{!ttl && (
<Alert severity="info">
Tokens with no TTL value will be valid forever.
</Alert>
)}
</Stack>
)

Expand Down

0 comments on commit 4a24b08

Please sign in to comment.