Require login
This commit is contained in:
@@ -6,9 +6,10 @@
|
|||||||
// During web development, you may change values here for rapid testing.
|
// During web development, you may change values here for rapid testing.
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
base_url: window.location.origin, // Change to test against a different server
|
base_url: "http://localhost:8080", // window.location.origin, // Change to test against a different server
|
||||||
app_root: "/",
|
app_root: "/",
|
||||||
enable_login: true,
|
enable_login: true,
|
||||||
|
require_login: true,
|
||||||
enable_signup: true,
|
enable_signup: true,
|
||||||
enable_payments: false,
|
enable_payments: false,
|
||||||
enable_reservations: true,
|
enable_reservations: true,
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export const maybeWithBearerAuth = (headers, token) => {
|
|||||||
|
|
||||||
export const withBasicAuth = (headers, username, password) => ({
|
export const withBasicAuth = (headers, username, password) => ({
|
||||||
...headers,
|
...headers,
|
||||||
Authorization: basicAuth(username, password)
|
Authorization: basicAuth(username, password),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const maybeWithAuth = (headers, user) => {
|
export const maybeWithAuth = (headers, user) => {
|
||||||
@@ -142,7 +142,7 @@ export const getKebabCaseLangStr = (language) => language.replace(/_/g, "-");
|
|||||||
export const formatShortDateTime = (timestamp, language) =>
|
export const formatShortDateTime = (timestamp, language) =>
|
||||||
new Intl.DateTimeFormat(getKebabCaseLangStr(language), {
|
new Intl.DateTimeFormat(getKebabCaseLangStr(language), {
|
||||||
dateStyle: "short",
|
dateStyle: "short",
|
||||||
timeStyle: "short"
|
timeStyle: "short",
|
||||||
}).format(new Date(timestamp * 1000));
|
}).format(new Date(timestamp * 1000));
|
||||||
|
|
||||||
export const formatShortDate = (timestamp, language) =>
|
export const formatShortDate = (timestamp, language) =>
|
||||||
@@ -181,32 +181,32 @@ export const openUrl = (url) => {
|
|||||||
export const sounds = {
|
export const sounds = {
|
||||||
ding: {
|
ding: {
|
||||||
file: ding,
|
file: ding,
|
||||||
label: "Ding"
|
label: "Ding",
|
||||||
},
|
},
|
||||||
juntos: {
|
juntos: {
|
||||||
file: juntos,
|
file: juntos,
|
||||||
label: "Juntos"
|
label: "Juntos",
|
||||||
},
|
},
|
||||||
pristine: {
|
pristine: {
|
||||||
file: pristine,
|
file: pristine,
|
||||||
label: "Pristine"
|
label: "Pristine",
|
||||||
},
|
},
|
||||||
dadum: {
|
dadum: {
|
||||||
file: dadum,
|
file: dadum,
|
||||||
label: "Dadum"
|
label: "Dadum",
|
||||||
},
|
},
|
||||||
pop: {
|
pop: {
|
||||||
file: pop,
|
file: pop,
|
||||||
label: "Pop"
|
label: "Pop",
|
||||||
},
|
},
|
||||||
"pop-swoosh": {
|
"pop-swoosh": {
|
||||||
file: popSwoosh,
|
file: popSwoosh,
|
||||||
label: "Pop swoosh"
|
label: "Pop swoosh",
|
||||||
},
|
},
|
||||||
beep: {
|
beep: {
|
||||||
file: beep,
|
file: beep,
|
||||||
label: "Beep"
|
label: "Beep",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const playSound = async (id) => {
|
export const playSound = async (id) => {
|
||||||
@@ -219,7 +219,7 @@ export const playSound = async (id) => {
|
|||||||
export async function* fetchLinesIterator(fileURL, headers) {
|
export async function* fetchLinesIterator(fileURL, headers) {
|
||||||
const utf8Decoder = new TextDecoder("utf-8");
|
const utf8Decoder = new TextDecoder("utf-8");
|
||||||
const response = await fetch(fileURL, {
|
const response = await fetch(fileURL, {
|
||||||
headers
|
headers,
|
||||||
});
|
});
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
let { value: chunk, done: readerDone } = await reader.read();
|
let { value: chunk, done: readerDone } = await reader.read();
|
||||||
@@ -228,7 +228,7 @@ export async function* fetchLinesIterator(fileURL, headers) {
|
|||||||
const re = /\n|\r|\r\n/gm;
|
const re = /\n|\r|\r\n/gm;
|
||||||
let startIndex = 0;
|
let startIndex = 0;
|
||||||
|
|
||||||
for (; ;) {
|
for (;;) {
|
||||||
const result = re.exec(chunk);
|
const result = re.exec(chunk);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (readerDone) {
|
if (readerDone) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import Account from "./Account";
|
|||||||
import initI18n from "../app/i18n"; // Translations!
|
import initI18n from "../app/i18n"; // Translations!
|
||||||
import prefs, { THEME } from "../app/Prefs";
|
import prefs, { THEME } from "../app/Prefs";
|
||||||
import RTLCacheProvider from "./RTLCacheProvider";
|
import RTLCacheProvider from "./RTLCacheProvider";
|
||||||
|
import session from "../app/Session";
|
||||||
|
|
||||||
initI18n();
|
initI18n();
|
||||||
|
|
||||||
@@ -45,7 +46,6 @@ const darkModeEnabled = (prefersDarkMode, themePreference) => {
|
|||||||
const App = () => {
|
const App = () => {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
const languageDir = i18n.dir();
|
const languageDir = i18n.dir();
|
||||||
|
|
||||||
const [account, setAccount] = useState(null);
|
const [account, setAccount] = useState(null);
|
||||||
const accountMemo = useMemo(() => ({ account, setAccount }), [account, setAccount]);
|
const accountMemo = useMemo(() => ({ account, setAccount }), [account, setAccount]);
|
||||||
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
||||||
@@ -60,6 +60,12 @@ const App = () => {
|
|||||||
document.dir = languageDir;
|
document.dir = languageDir;
|
||||||
}, [i18n.language, languageDir]);
|
}, [i18n.language, languageDir]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!session.exists() && config.require_login && window.location.pathname !== routes.login) {
|
||||||
|
window.location.href = routes.login;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<Loader />}>
|
<Suspense fallback={<Loader />}>
|
||||||
<RTLCacheProvider>
|
<RTLCacheProvider>
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ import { useRemark } from "react-remark";
|
|||||||
import styled from "@emotion/styled";
|
import styled from "@emotion/styled";
|
||||||
import {
|
import {
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
formatBytes, formatShortDateTime, maybeActionErrors, openUrl, shortUrl, topicShortUrl, unmatchedTags
|
formatBytes,
|
||||||
|
formatShortDateTime,
|
||||||
|
maybeActionErrors,
|
||||||
|
openUrl,
|
||||||
|
shortUrl,
|
||||||
|
topicShortUrl,
|
||||||
|
unmatchedTags,
|
||||||
} from "../app/utils";
|
} from "../app/utils";
|
||||||
import { formatMessage, formatTitle, isImage } from "../app/notificationUtils";
|
import { formatMessage, formatTitle, isImage } from "../app/notificationUtils";
|
||||||
import { LightboxBackdrop, Paragraph, VerticallyCenteredContainer } from "./styles";
|
import { LightboxBackdrop, Paragraph, VerticallyCenteredContainer } from "./styles";
|
||||||
|
|||||||
Reference in New Issue
Block a user