Skip to content

Commit

Permalink
Changed HASH_SALT to APP_SECRET.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Dec 28, 2022
1 parent cad0b73 commit 7bbed0e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 70 deletions.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions components/forms/WebsiteEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 7 additions & 65 deletions hooks/useApi.js
Original file line number Diff line number Diff line change
@@ -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],
),

post: useCallback(
async (url, params = {}, headers = {}) => {
return post(
`${basePath}/api${url}`,
params,
parseHeaders(headers, { authToken, shareToken }),
);
},
[post],
),
const { get, post, put, del } = nextUseApi(getClientAuthToken(), basePath);

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;
2 changes: 1 addition & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7bbed0e

Please sign in to comment.