Compare commits
4 Commits
master
...
dashboard-
Author | SHA1 | Date |
---|---|---|
Michał Leszczyk | 87f6352d06 | |
Michał Leszczyk | 91be333fb9 | |
Michał Leszczyk | 1a0fb9a806 | |
Michał Leszczyk | a3b21edf0c |
|
@ -21,8 +21,8 @@ services:
|
||||||
|
|
||||||
accounts:
|
accounts:
|
||||||
# uncomment "build" and comment out "image" to build from sources
|
# uncomment "build" and comment out "image" to build from sources
|
||||||
# build: https://github.com/SkynetLabs/skynet-accounts.git#main
|
build: https://github.com/SkynetLabs/skynet-accounts.git#main
|
||||||
image: skynetlabs/skynet-accounts
|
# image: skynetlabs/skynet-accounts
|
||||||
container_name: accounts
|
container_name: accounts
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
logging: *default-logging
|
logging: *default-logging
|
||||||
|
@ -75,3 +75,25 @@ services:
|
||||||
- 3000
|
- 3000
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
- mongo
|
||||||
|
|
||||||
|
dashboard-v2:
|
||||||
|
build:
|
||||||
|
context: ./packages/dashboard-v2
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: dashboard-v2
|
||||||
|
restart: unless-stopped
|
||||||
|
logging: *default-logging
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- GATSBY_PORTAL_DOMAIN=${PORTAL_DOMAIN}
|
||||||
|
volumes:
|
||||||
|
- ./docker/data/dashboard-v2/.cache:/usr/app/.cache
|
||||||
|
- ./docker/data/dashboard-v2/public:/usr/app/public
|
||||||
|
networks:
|
||||||
|
shared:
|
||||||
|
ipv4_address: 10.10.10.90
|
||||||
|
expose:
|
||||||
|
- 9000
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
|
|
@ -4,7 +4,7 @@ include /etc/nginx/conf.d/include/ssl-settings;
|
||||||
include /etc/nginx/conf.d/include/init-optional-variables;
|
include /etc/nginx/conf.d/include/init-optional-variables;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://dashboard:3000;
|
proxy_pass http://dashboard-v2:9000;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /health {
|
location /health {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM node:16.14.2-alpine
|
||||||
|
|
||||||
|
WORKDIR /usr/app
|
||||||
|
|
||||||
|
COPY package.json yarn.lock ./
|
||||||
|
|
||||||
|
RUN yarn --frozen-lockfile
|
||||||
|
|
||||||
|
COPY static ./static
|
||||||
|
COPY src ./src
|
||||||
|
COPY gatsby*.js ./
|
||||||
|
COPY postcss.config.js tailwind.config.js ./
|
||||||
|
|
||||||
|
CMD ["sh", "-c", "yarn build && yarn serve --host 0.0.0.0 -p 9000"]
|
|
@ -18,7 +18,7 @@ module.exports = {
|
||||||
resolve: "gatsby-source-filesystem",
|
resolve: "gatsby-source-filesystem",
|
||||||
options: {
|
options: {
|
||||||
name: "images",
|
name: "images",
|
||||||
path: "./src/images/",
|
path: "./static/images/",
|
||||||
},
|
},
|
||||||
__key: "images",
|
__key: "images",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
|
import { navigate } from "gatsby";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import useSWRImmutable from "swr/immutable";
|
import useSWRImmutable from "swr/immutable";
|
||||||
|
import { UnauthorizedError } from "../../lib/swrConfig";
|
||||||
|
|
||||||
import { UserContext } from "./UserContext";
|
import { UserContext } from "./UserContext";
|
||||||
|
|
||||||
export const UserProvider = ({ children }) => {
|
export const UserProvider = ({ children, allowGuests = false, allowAuthenticated = true }) => {
|
||||||
const { data: user, error, mutate } = useSWRImmutable("user");
|
const { data: user, error, mutate } = useSWRImmutable("user");
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user || error) {
|
if (user) {
|
||||||
setLoading(false);
|
if (!allowAuthenticated) {
|
||||||
|
navigate("/");
|
||||||
|
} else {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
} else if (error) {
|
||||||
|
if (error instanceof UnauthorizedError && !allowGuests) {
|
||||||
|
navigate(`/auth/login?return_to=${encodeURIComponent(window.location.href)}`);
|
||||||
|
} else {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [user, error]);
|
}, [user, error, allowGuests, allowAuthenticated]);
|
||||||
|
|
||||||
return <UserContext.Provider value={{ user, error, loading, mutate }}>{children}</UserContext.Provider>;
|
return <UserContext.Provider value={{ user, error, loading, mutate }}>{children}</UserContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,6 @@ export default function useUpgradeRedirect() {
|
||||||
|
|
||||||
if (isDataLoaded) {
|
if (isDataLoaded) {
|
||||||
if (settings.isSubscriptionRequired && !hasPaidSubscription) {
|
if (settings.isSubscriptionRequired && !hasPaidSubscription) {
|
||||||
console.log("redirecting", user, settings);
|
|
||||||
navigate("/upgrade");
|
navigate("/upgrade");
|
||||||
} else {
|
} else {
|
||||||
setVerifyingSubscription(false);
|
setVerifyingSubscription(false);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import styled from "styled-components";
|
||||||
import { SWRConfig } from "swr";
|
import { SWRConfig } from "swr";
|
||||||
|
|
||||||
import { UserProvider } from "../contexts/user";
|
import { UserProvider } from "../contexts/user";
|
||||||
import { guestsOnly, allUsers } from "../lib/swrConfig";
|
import { allUsers } from "../lib/swrConfig";
|
||||||
|
|
||||||
const Layout = styled.div.attrs({
|
const Layout = styled.div.attrs({
|
||||||
className: "min-h-screen w-screen bg-black flex",
|
className: "min-h-screen w-screen bg-black flex",
|
||||||
|
@ -22,12 +22,12 @@ const Content = styled.div.attrs({
|
||||||
})``;
|
})``;
|
||||||
|
|
||||||
const AuthLayout =
|
const AuthLayout =
|
||||||
(swrConfig) =>
|
(userProviderProps) =>
|
||||||
({ children }) => {
|
({ children }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SWRConfig value={swrConfig}>
|
<SWRConfig value={allUsers}>
|
||||||
<UserProvider>
|
<UserProvider {...userProviderProps}>
|
||||||
<Layout>
|
<Layout>
|
||||||
<SloganContainer className="pl-20 pr-20 lg:pr-30 xl:pr-40">
|
<SloganContainer className="pl-20 pr-20 lg:pr-30 xl:pr-40">
|
||||||
<div className="">
|
<div className="">
|
||||||
|
@ -45,6 +45,12 @@ const AuthLayout =
|
||||||
};
|
};
|
||||||
|
|
||||||
// Some pages (e.g. email confirmation) need to be accessible to both logged-in and guest users.
|
// Some pages (e.g. email confirmation) need to be accessible to both logged-in and guest users.
|
||||||
export const AllUsersAuthLayout = AuthLayout(allUsers);
|
export const AllUsersAuthLayout = AuthLayout({
|
||||||
|
allowGuests: true,
|
||||||
|
allowAuthenticated: true,
|
||||||
|
});
|
||||||
|
|
||||||
export default AuthLayout(guestsOnly);
|
export default AuthLayout({
|
||||||
|
allowGuests: true,
|
||||||
|
allowAuthenticated: false,
|
||||||
|
});
|
||||||
|
|
|
@ -2,10 +2,10 @@ import * as React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { SWRConfig } from "swr";
|
import { SWRConfig } from "swr";
|
||||||
|
|
||||||
import { authenticatedOnly } from "../lib/swrConfig";
|
import { allUsers } from "../lib/swrConfig";
|
||||||
|
|
||||||
import { PageContainer } from "../components/PageContainer";
|
import { PageContainer } from "../components/PageContainer";
|
||||||
import { NavBar } from "../components/Navbar";
|
import { NavBar } from "../components/NavBar";
|
||||||
import { Footer } from "../components/Footer";
|
import { Footer } from "../components/Footer";
|
||||||
import { UserProvider, useUser } from "../contexts/user";
|
import { UserProvider, useUser } from "../contexts/user";
|
||||||
import { FullScreenLoadingIndicator } from "../components/LoadingIndicator";
|
import { FullScreenLoadingIndicator } from "../components/LoadingIndicator";
|
||||||
|
@ -33,8 +33,8 @@ const Layout = ({ children }) => {
|
||||||
const DashboardLayout = ({ children }) => {
|
const DashboardLayout = ({ children }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SWRConfig value={authenticatedOnly}>
|
<SWRConfig value={allUsers}>
|
||||||
<UserProvider>
|
<UserProvider allowAuthenticated>
|
||||||
<Layout>
|
<Layout>
|
||||||
<NavBar />
|
<NavBar />
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { Link } from "gatsby";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { SWRConfig } from "swr";
|
import { SWRConfig } from "swr";
|
||||||
|
|
||||||
import { authenticatedOnly } from "../lib/swrConfig";
|
import { allUsers } from "../lib/swrConfig";
|
||||||
|
|
||||||
import { PageContainer } from "../components/PageContainer";
|
import { PageContainer } from "../components/PageContainer";
|
||||||
import { NavBar } from "../components/Navbar";
|
import { NavBar } from "../components/NavBar";
|
||||||
import { Footer } from "../components/Footer";
|
import { Footer } from "../components/Footer";
|
||||||
import { UserProvider, useUser } from "../contexts/user";
|
import { UserProvider, useUser } from "../contexts/user";
|
||||||
import { ContainerLoadingIndicator } from "../components/LoadingIndicator";
|
import { ContainerLoadingIndicator } from "../components/LoadingIndicator";
|
||||||
|
@ -67,8 +67,8 @@ const Content = styled.main.attrs({
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const UserSettingsLayout = ({ children }) => (
|
const UserSettingsLayout = ({ children }) => (
|
||||||
<SWRConfig value={authenticatedOnly}>
|
<SWRConfig value={allUsers}>
|
||||||
<UserProvider>
|
<UserProvider allowAuthenticated>
|
||||||
<Layout>
|
<Layout>
|
||||||
<NavBar />
|
<NavBar />
|
||||||
<PageContainer className="mt-2 md:mt-14">
|
<PageContainer className="mt-2 md:mt-14">
|
||||||
|
|
|
@ -1,39 +1,19 @@
|
||||||
import { navigate } from "gatsby";
|
|
||||||
import { StatusCodes } from "http-status-codes";
|
import { StatusCodes } from "http-status-codes";
|
||||||
|
|
||||||
// TODO: portal-aware URL
|
export class UnauthorizedError extends Error {}
|
||||||
const baseUrl = process.env.NODE_ENV !== "production" ? "/api" : "https://account.skynetpro.net/api";
|
|
||||||
|
|
||||||
const redirectUnauthenticated = (key) =>
|
|
||||||
fetch(`${baseUrl}/${key}`).then((response) => {
|
|
||||||
if (response.status === StatusCodes.UNAUTHORIZED) {
|
|
||||||
navigate(`/auth/login?return_to=${encodeURIComponent(window.location.href)}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
});
|
|
||||||
|
|
||||||
const redirectAuthenticated = (key) =>
|
|
||||||
fetch(`${baseUrl}/${key}`).then(async (response) => {
|
|
||||||
if (response.ok) {
|
|
||||||
await navigate("/");
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there was an error, let's throw so useSWR's "error" property is populated instead "data".
|
|
||||||
const data = await response.json();
|
|
||||||
throw new Error(data?.message || `Error occured when trying to fetch: ${key}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
export const allUsers = {
|
export const allUsers = {
|
||||||
fetcher: (key) => fetch(`${baseUrl}/${key}`).then((response) => response.json()),
|
fetcher: (key) => fetch(`/api/${key}`).then(async (response) => {
|
||||||
};
|
if (response.ok) {
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
export const authenticatedOnly = {
|
if (response.status === StatusCodes.UNAUTHORIZED) {
|
||||||
fetcher: redirectUnauthenticated,
|
throw new UnauthorizedError(data?.message || "Unauthorized");
|
||||||
};
|
}
|
||||||
|
|
||||||
export const guestsOnly = {
|
throw new Error(data?.message || `Error occurred when trying to fetch: ${key}`);
|
||||||
fetcher: redirectAuthenticated,
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ const FreePortalHeader = () => {
|
||||||
const { plans } = usePlans();
|
const { plans } = usePlans();
|
||||||
|
|
||||||
const freePlan = plans.find(({ price }) => price === 0);
|
const freePlan = plans.find(({ price }) => price === 0);
|
||||||
const freeStorage = freePlan ? bytes(freePlan.limits?.storageLimit, { binary: true }) : null;
|
const freeStorage = freePlan?.limits ? bytes(freePlan.limits?.storageLimit, { binary: true }) : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 mb-8 font-sans">
|
<div className="mt-4 mb-8 font-sans">
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import { SkynetClient } from "skynet-js";
|
import { SkynetClient } from "skynet-js";
|
||||||
|
|
||||||
export default new SkynetClient("https://skynetpro.net"); // TODO: proper API url
|
export default new SkynetClient(`https://${process.env.GATSBY_PORTAL_DOMAIN}`);
|
||||||
|
|
|
@ -14090,7 +14090,7 @@ sjcl@^1.0.8:
|
||||||
resolved "https://registry.yarnpkg.com/sjcl/-/sjcl-1.0.8.tgz#f2ec8d7dc1f0f21b069b8914a41a8f236b0e252a"
|
resolved "https://registry.yarnpkg.com/sjcl/-/sjcl-1.0.8.tgz#f2ec8d7dc1f0f21b069b8914a41a8f236b0e252a"
|
||||||
integrity sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ==
|
integrity sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ==
|
||||||
|
|
||||||
skynet-js@^4.0.27-beta:
|
skynet-js@4.0.27-beta:
|
||||||
version "4.0.27-beta"
|
version "4.0.27-beta"
|
||||||
resolved "https://registry.yarnpkg.com/skynet-js/-/skynet-js-4.0.27-beta.tgz#4257bffda8757830656e0beb89d0d2e44da17e2f"
|
resolved "https://registry.yarnpkg.com/skynet-js/-/skynet-js-4.0.27-beta.tgz#4257bffda8757830656e0beb89d0d2e44da17e2f"
|
||||||
integrity sha512-JV+QE/2l2YwVN1jQHVMFXgggwtBrPAnuyXySbLgafEJAde5dUwSEr5YRMV+3LvEgYkGhxSb74pyq0u0wrF2sUg==
|
integrity sha512-JV+QE/2l2YwVN1jQHVMFXgggwtBrPAnuyXySbLgafEJAde5dUwSEr5YRMV+3LvEgYkGhxSb74pyq0u0wrF2sUg==
|
||||||
|
|
Reference in New Issue