mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
using param based token
This commit is contained in:
parent
f5e0ef29f8
commit
9bb2a4ac7c
@ -8,6 +8,10 @@ function checkResponse(response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getProfileImageUrl(token) {
|
||||||
|
return '/profile/image?agent=' + token
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchWithTimeout(url, options) {
|
async function fetchWithTimeout(url, options) {
|
||||||
return Promise.race([
|
return Promise.race([
|
||||||
fetch(url, options).catch(err => { throw new Error(url + ' failed'); }),
|
fetch(url, options).catch(err => { throw new Error(url + ' failed'); }),
|
||||||
@ -45,18 +49,17 @@ export async function createAccount(username, password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getProfile(token) {
|
export async function getProfile(token) {
|
||||||
let headers = new Headers()
|
let profile = await fetchWithTimeout('/profile?agent=' + token, { method: 'GET', timeout: FETCH_TIMEOUT });
|
||||||
headers.append('Authorization', 'Bearer ' + token);
|
|
||||||
let profile = await fetchWithTimeout('/profile', { method: 'GET', timeout: FETCH_TIMEOUT, headers: headers });
|
|
||||||
checkResponse(profile)
|
checkResponse(profile)
|
||||||
return await profile.json()
|
return await profile.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroups(token, revision) {
|
export async function getGroups(token, revision) {
|
||||||
let headers = new Headers()
|
let param = "?agent=" + token
|
||||||
headers.append('Authorization', 'Bearer ' + token);
|
if (revision != null) {
|
||||||
let param = revision == null ? '' : '?revision=' + revision
|
param += '&revision=' + revision
|
||||||
let groups = await fetchWithTimeout('/alias/groups' + param, { method: 'GET', timeout: FETCH_TIMEOUT, headers: headers });
|
}
|
||||||
|
let groups = await fetchWithTimeout('/alias/groups' + param, { method: 'GET', timeout: FETCH_TIMEOUT });
|
||||||
checkResponse(groups)
|
checkResponse(groups)
|
||||||
return await groups.json()
|
return await groups.json()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, useRef } from 'react';
|
import { useEffect, useState, useRef } from 'react';
|
||||||
import { getProfile, getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil';
|
import { getProfileImageUrl, getProfile, getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil';
|
||||||
|
|
||||||
async function updateProfile(token, updateData) {
|
async function updateProfile(token, updateData) {
|
||||||
let profile = await getProfile(token);
|
let profile = await getProfile(token);
|
||||||
@ -70,7 +70,8 @@ export function useAppContext() {
|
|||||||
logout: () => {
|
logout: () => {
|
||||||
appLogout(updateState, clearWebsocket);
|
appLogout(updateState, clearWebsocket);
|
||||||
resetData();
|
resetData();
|
||||||
}
|
},
|
||||||
|
profileImageUrl: () => getProfileImageUrl(state.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminActions = {
|
const adminActions = {
|
||||||
|
@ -37,7 +37,7 @@ export function useIdentity() {
|
|||||||
updateState({ name: profile.name });
|
updateState({ name: profile.name });
|
||||||
}
|
}
|
||||||
if (profile.image != null) {
|
if (profile.image != null) {
|
||||||
updateState({ imageUrl: 'https://' + profile.node + '/profile/image?token=' + app.state.token })
|
updateState({ imageUrl: app.actions.profileImageUrl() })
|
||||||
} else {
|
} else {
|
||||||
updateState({ imageUrl: '' })
|
updateState({ imageUrl: '' })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user