some changes / fixes

This commit is contained in:
mbecker20
2022-03-13 01:26:26 -08:00
parent b73149516a
commit 31d79fb67b
9 changed files with 27 additions and 50 deletions
+3
View File
@@ -4,6 +4,9 @@
"main": "index.js",
"author": "mbecker20",
"license": "MIT",
"scripts": {
"start": "tsc && node build/main.js"
},
"devDependencies": {
"@types/dockerode": "^3.3.3",
"@types/fs-extra": "^9.0.13",
+3 -9
View File
@@ -1,19 +1,13 @@
import { Component, createEffect, createResource, Match, Switch } from "solid-js";
import { client, redirectTo } from "../..";
import { Component, createResource, Match, Switch } from "solid-js";
import { client } from "../..";
import styles from "./App.module.css";
import UserInfo from "../UserInfo";
import { User } from "@oauth2/types"
import { User } from "@monitor/types"
import Login from "../Login";
const App: Component = () => {
const [user, { mutate }] = createResource(() => client.getUser());
createEffect(() => {
if (redirectTo && user()) {
location.replace(`${redirectTo.url}/?token=${client.token}`)
}
})
return (
<div class={styles.App}>
<Switch>
+2 -3
View File
@@ -1,11 +1,11 @@
import { Component } from "solid-js";
import { loginGithub, loginGoogle } from "../util/helpers";
import { loginGithub } from "../util/helpers";
import Input from "./util/Input";
import Grid from "./util/layout/Grid";
import { createStore } from "solid-js/store";
import Flex from "./util/layout/Flex";
import { client, pushNotification } from "..";
import { User } from "@oauth2/types";
import { User } from "@monitor/types";
const Login: Component<{ setUser: (user: User | false) => void }> = (p) => {
const [info, set] = createStore({
@@ -60,7 +60,6 @@ const Login: Component<{ setUser: (user: User | false) => void }> = (p) => {
<button onClick={signup}>sign up</button>
</Flex>
<button onClick={loginGithub}>log in with github</button>
<button onClick={loginGoogle}>log in with google</button>
</Grid>
);
};
+1 -4
View File
@@ -2,7 +2,7 @@ import { Component, Show } from "solid-js";
import { getAuthProvider } from "../util/helpers";
import Flex from "./util/layout/Flex";
import Grid from "./util/layout/Grid";
import { User } from "@oauth2/types";
import { User } from "@monitor/types";
import { pushNotification } from "..";
const UserInfo: Component<{ user: User; logout: () => void }> = (p) => {
@@ -15,9 +15,6 @@ const UserInfo: Component<{ user: User; logout: () => void }> = (p) => {
<img src={p.user.avatar} style={{ width: "2rem", height: "2rem" }} />
</Show>
</Flex>
<Show when={p.user.email}>
<div>email: {p.user.email}</div>
</Show>
<button style={{ width: "100%" }} onClick={() => {
p.logout();
pushNotification("ok", "logged out");
-2
View File
@@ -4,12 +4,10 @@ import { render } from 'solid-js/web';
import './index.css';
import App from './components/App/App';
import Client from './util/client';
import { getRedirectTo } from './util/helpers';
import makeNotifications from './components/util/notification/Notifications';
export const URL = "http://localhost:2020";
export const client = new Client(URL);
export const redirectTo = getRedirectTo();
export const { Notifications, pushNotification } = makeNotifications();
+1 -1
View File
@@ -1,6 +1,6 @@
import axios from "axios";
import { URL } from "..";
import { User } from "@oauth2/types";
import { User } from "@monitor/types";
export default class Client {
token = localStorage.getItem("access_token");
+8 -31
View File
@@ -1,44 +1,21 @@
import { client, redirectTo, URL } from "..";
import { User } from "@oauth2/types";
import axios from "axios";
import { URL } from "..";
import { User } from "@monitor/types";
export function combineClasses(...classes: (string | undefined)[]) {
return classes.filter((c) => (c ? true : false)).join(" ");
}
export function getAuthProvider(user: User) {
if (user.githubID) return "Github";
else if (user.googleID) return "Google";
else return "Local";
export function inPx(num: number) {
return `${num}px`;
}
export function getRedirectTo() {
const params = new URLSearchParams(location.search);
const redirect = params.get("redirect");
if (redirect) {
if (redirect === "consumer") {
return {
service: "consumer",
url: "http://localhost:3000"
}
}
}
export function getAuthProvider(user: User) {
if (user.githubID) return "Github";
else return "Local";
}
export function loginGithub() {
window.location.replace(
`${URL}/login/github${redirectTo ? "/" + redirectTo.service : ""}`
`${URL}/login/github`
);
}
export function loginGoogle() {
window.location.replace(
`${URL}/login/google${
redirectTo ? "/" + redirectTo.service : ""
}`
);
}
export function inPx(num: number) {
return `${num}px`;
}
+3
View File
@@ -4,6 +4,9 @@
"main": "index.js",
"author": "mbecker20",
"license": "MIT",
"scripts": {
"start": "tsc && node build/main.js"
},
"devDependencies": {
"@types/dockerode": "^3.3.3",
"typescript": "^4.6.2"
+6
View File
@@ -0,0 +1,6 @@
export type User = {
_id: string;
username: string;
githubID?: string;
avatar?: string;
}