mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
Refactor profile page (#1636)
This commit is contained in:
parent
394b8bd199
commit
f1117dbad3
23 changed files with 765 additions and 339 deletions
|
@ -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'
|
||||
})
|
||||
|
|
7
src/api/tokens/types.d.ts
vendored
7
src/api/tokens/types.d.ts
vendored
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue