Refactor profile page (#1636)

This commit is contained in:
Erik Michelson 2021-12-02 23:03:03 +01:00 committed by GitHub
parent 394b8bd199
commit f1117dbad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 765 additions and 339 deletions

View file

@ -5,7 +5,7 @@
*/
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import type { AccessToken, AccessTokenSecret } from './types'
import type { AccessToken, AccessTokenWithSecret } from './types'
export const getAccessTokenList = async (): Promise<AccessToken[]> => {
const response = await fetch(`${getApiUrl()}tokens`, {
@ -15,18 +15,21 @@ export const getAccessTokenList = async (): Promise<AccessToken[]> => {
return (await response.json()) as AccessToken[]
}
export const postNewAccessToken = async (label: string): Promise<AccessToken & AccessTokenSecret> => {
export const postNewAccessToken = async (label: string, expiryDate: string): Promise<AccessTokenWithSecret> => {
const response = await fetch(`${getApiUrl()}tokens`, {
...defaultFetchConfig,
method: 'POST',
body: label
body: JSON.stringify({
label: label,
validUntil: expiryDate
})
})
expectResponseCode(response)
return (await response.json()) as AccessToken & AccessTokenSecret
return (await response.json()) as AccessTokenWithSecret
}
export const deleteAccessToken = async (timestamp: number): Promise<void> => {
const response = await fetch(`${getApiUrl()}tokens/${timestamp}`, {
export const deleteAccessToken = async (keyId: string): Promise<void> => {
const response = await fetch(`${getApiUrl()}tokens/${keyId}`, {
...defaultFetchConfig,
method: 'DELETE'
})

View file

@ -6,9 +6,12 @@
export interface AccessToken {
label: string
created: number
validUntil: string
keyId: string
createdAt: string
lastUsed: string
}
export interface AccessTokenSecret {
export interface AccessTokenWithSecret extends AccessToken {
secret: string
}