Add access token management to profile (#653)

* Add mock-files, API calls and overall tokens-UI

* Added ability to add tokens

* Added token deletion feature (based on timestamp)

* Replace mock-method by real API code

* Add cypress tests

* Added CHANGELOG information

* Un-access-ify i18n

* Set unique react-element key to timestamp of token-creation

* Remove 'now' from changelog

* Use @mrdrogdrog's suggestion for the info label
This commit is contained in:
Erik Michelson 2020-10-10 11:38:32 +02:00 committed by GitHub
parent f72380edd1
commit 053edb9ace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 302 additions and 4 deletions

28
src/api/tokens/index.ts Normal file
View file

@ -0,0 +1,28 @@
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import { AccessToken, AccessTokenSecret } from './types'
export const getAccessTokenList = async (): Promise<AccessToken[]> => {
const response = await fetch(`${getApiUrl()}/tokens`, {
...defaultFetchConfig
})
expectResponseCode(response)
return await response.json() as AccessToken[]
}
export const postNewAccessToken = async (label: string): Promise<AccessToken & AccessTokenSecret> => {
const response = await fetch(`${getApiUrl()}/tokens`, {
...defaultFetchConfig,
method: 'POST',
body: label
})
expectResponseCode(response)
return await response.json() as (AccessToken & AccessTokenSecret)
}
export const deleteAccessToken = async (timestamp: number): Promise<void> => {
const response = await fetch(`${getApiUrl()}/tokens/${timestamp}`, {
...defaultFetchConfig,
method: 'DELETE'
})
expectResponseCode(response)
}

8
src/api/tokens/types.d.ts vendored Normal file
View file

@ -0,0 +1,8 @@
export interface AccessToken {
label: string
created: number
}
export interface AccessTokenSecret {
secret: string
}