mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
Changed HASH_SALT to APP_SECRET.
This commit is contained in:
parent
cad0b73e42
commit
7bbed0e12b
2
app.json
2
app.json
@ -6,7 +6,7 @@
|
||||
"repository": "https://github.com/umami-software/umami",
|
||||
"addons": ["heroku-postgresql"],
|
||||
"env": {
|
||||
"HASH_SALT": {
|
||||
"APP_SECRET": {
|
||||
"description": "Used to generate unique values for your installation",
|
||||
"required": true,
|
||||
"generator": "secret"
|
||||
|
@ -2,11 +2,10 @@ import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from '
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRef } from 'react';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { getClientAuthToken } from 'lib/client';
|
||||
import { DOMAIN_REGEX } from 'lib/constants';
|
||||
|
||||
export default function WebsiteEditForm({ websiteId, data, onSave }) {
|
||||
const { post } = useApi(getClientAuthToken());
|
||||
const { post } = useApi();
|
||||
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}`, data));
|
||||
const ref = useRef(null);
|
||||
|
||||
|
@ -8,7 +8,7 @@ services:
|
||||
environment:
|
||||
DATABASE_URL: postgresql://umami:umami@db:5432/umami
|
||||
DATABASE_TYPE: postgresql
|
||||
HASH_SALT: replace-me-with-a-random-string
|
||||
APP_SECRET: replace-me-with-a-random-string
|
||||
depends_on:
|
||||
- db
|
||||
restart: always
|
||||
|
@ -1,71 +1,13 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useApi as nextUseApi } from 'next-basics';
|
||||
import { getClientAuthToken } from 'lib/client';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get, post, put, del, getItem } from 'next-basics';
|
||||
import { AUTH_TOKEN, SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
import useStore from 'store/app';
|
||||
|
||||
const selector = state => state.shareToken;
|
||||
|
||||
function parseHeaders(headers, { authToken, shareToken }) {
|
||||
if (authToken) {
|
||||
headers.authorization = `Bearer ${authToken}`;
|
||||
}
|
||||
|
||||
if (shareToken) {
|
||||
headers[SHARE_TOKEN_HEADER] = shareToken.token;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
export default function useApi() {
|
||||
export function useApi() {
|
||||
const { basePath } = useRouter();
|
||||
const authToken = getItem(AUTH_TOKEN);
|
||||
const shareToken = useStore(selector);
|
||||
|
||||
return {
|
||||
get: useCallback(
|
||||
async (url, params = {}, headers = {}) => {
|
||||
return get(
|
||||
`${basePath}/api${url}`,
|
||||
params,
|
||||
parseHeaders(headers, { authToken, shareToken }),
|
||||
);
|
||||
},
|
||||
[get],
|
||||
),
|
||||
const { get, post, put, del } = nextUseApi(getClientAuthToken(), basePath);
|
||||
|
||||
post: useCallback(
|
||||
async (url, params = {}, headers = {}) => {
|
||||
return post(
|
||||
`${basePath}/api${url}`,
|
||||
params,
|
||||
parseHeaders(headers, { authToken, shareToken }),
|
||||
);
|
||||
},
|
||||
[post],
|
||||
),
|
||||
|
||||
put: useCallback(
|
||||
async (url, params = {}, headers = {}) => {
|
||||
return put(
|
||||
`${basePath}/api${url}`,
|
||||
params,
|
||||
parseHeaders(headers, { authToken, shareToken }),
|
||||
);
|
||||
},
|
||||
[put],
|
||||
),
|
||||
|
||||
del: useCallback(
|
||||
async (url, params = {}, headers = {}) => {
|
||||
return del(
|
||||
`${basePath}/api${url}`,
|
||||
params,
|
||||
parseHeaders(headers, { authToken, shareToken }),
|
||||
);
|
||||
},
|
||||
[del],
|
||||
),
|
||||
};
|
||||
return { get, post, put, del };
|
||||
}
|
||||
|
||||
export default useApi;
|
||||
|
@ -3,7 +3,7 @@ import { startOfMonth } from 'date-fns';
|
||||
import { hash } from 'next-basics';
|
||||
|
||||
export function secret() {
|
||||
return hash(process.env.HASH_SALT || process.env.DATABASE_URL);
|
||||
return hash(process.env.APP_SECRET || process.env.DATABASE_URL);
|
||||
}
|
||||
|
||||
export function salt() {
|
||||
|
Loading…
Reference in New Issue
Block a user