Skip to content

Commit 7bbed0e

Browse files
committed
Changed HASH_SALT to APP_SECRET.
1 parent cad0b73 commit 7bbed0e

File tree

5 files changed

+11
-70
lines changed

5 files changed

+11
-70
lines changed

app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"repository": "https://github.com/umami-software/umami",
77
"addons": ["heroku-postgresql"],
88
"env": {
9-
"HASH_SALT": {
9+
"APP_SECRET": {
1010
"description": "Used to generate unique values for your installation",
1111
"required": true,
1212
"generator": "secret"

components/forms/WebsiteEditForm.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from '
22
import { useMutation } from '@tanstack/react-query';
33
import { useRef } from 'react';
44
import useApi from 'hooks/useApi';
5-
import { getClientAuthToken } from 'lib/client';
65
import { DOMAIN_REGEX } from 'lib/constants';
76

87
export default function WebsiteEditForm({ websiteId, data, onSave }) {
9-
const { post } = useApi(getClientAuthToken());
8+
const { post } = useApi();
109
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}`, data));
1110
const ref = useRef(null);
1211

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
environment:
99
DATABASE_URL: postgresql://umami:umami@db:5432/umami
1010
DATABASE_TYPE: postgresql
11-
HASH_SALT: replace-me-with-a-random-string
11+
APP_SECRET: replace-me-with-a-random-string
1212
depends_on:
1313
- db
1414
restart: always

hooks/useApi.js

+7-65
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,13 @@
1-
import { useCallback } from 'react';
1+
import { useApi as nextUseApi } from 'next-basics';
2+
import { getClientAuthToken } from 'lib/client';
23
import { useRouter } from 'next/router';
3-
import { get, post, put, del, getItem } from 'next-basics';
4-
import { AUTH_TOKEN, SHARE_TOKEN_HEADER } from 'lib/constants';
5-
import useStore from 'store/app';
64

7-
const selector = state => state.shareToken;
8-
9-
function parseHeaders(headers, { authToken, shareToken }) {
10-
if (authToken) {
11-
headers.authorization = `Bearer ${authToken}`;
12-
}
13-
14-
if (shareToken) {
15-
headers[SHARE_TOKEN_HEADER] = shareToken.token;
16-
}
17-
18-
return headers;
19-
}
20-
21-
export default function useApi() {
5+
export function useApi() {
226
const { basePath } = useRouter();
23-
const authToken = getItem(AUTH_TOKEN);
24-
const shareToken = useStore(selector);
25-
26-
return {
27-
get: useCallback(
28-
async (url, params = {}, headers = {}) => {
29-
return get(
30-
`${basePath}/api${url}`,
31-
params,
32-
parseHeaders(headers, { authToken, shareToken }),
33-
);
34-
},
35-
[get],
36-
),
377

38-
post: useCallback(
39-
async (url, params = {}, headers = {}) => {
40-
return post(
41-
`${basePath}/api${url}`,
42-
params,
43-
parseHeaders(headers, { authToken, shareToken }),
44-
);
45-
},
46-
[post],
47-
),
8+
const { get, post, put, del } = nextUseApi(getClientAuthToken(), basePath);
489

49-
put: useCallback(
50-
async (url, params = {}, headers = {}) => {
51-
return put(
52-
`${basePath}/api${url}`,
53-
params,
54-
parseHeaders(headers, { authToken, shareToken }),
55-
);
56-
},
57-
[put],
58-
),
59-
60-
del: useCallback(
61-
async (url, params = {}, headers = {}) => {
62-
return del(
63-
`${basePath}/api${url}`,
64-
params,
65-
parseHeaders(headers, { authToken, shareToken }),
66-
);
67-
},
68-
[del],
69-
),
70-
};
10+
return { get, post, put, del };
7111
}
12+
13+
export default useApi;

lib/crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { startOfMonth } from 'date-fns';
33
import { hash } from 'next-basics';
44

55
export function secret() {
6-
return hash(process.env.HASH_SALT || process.env.DATABASE_URL);
6+
return hash(process.env.APP_SECRET || process.env.DATABASE_URL);
77
}
88

99
export function salt() {

0 commit comments

Comments
 (0)