Skip to content

Commit

Permalink
feat: v3 auth rework - fix #146 (#160)
Browse files Browse the repository at this point in the history
* feat: v3 auth rework - fix #146

* feat: v3 auth rework - fix #146
  • Loading branch information
pagoru authored Nov 26, 2024
1 parent 7e69442 commit c35bdd4
Show file tree
Hide file tree
Showing 198 changed files with 3,784 additions and 2,661 deletions.
3 changes: 2 additions & 1 deletion app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"react-dom": "18.3.1",
"react-router": "6.26.0",
"react-router-dom": "6.26.0",
"sass": "1.77.8"
"sass": "1.77.8",
"dayjs": "1.11.13"
},
"packageManager": "[email protected]",
"scripts": {
Expand Down
101 changes: 0 additions & 101 deletions app/client/src/modules/account/account.component.tsx

This file was deleted.

106 changes: 0 additions & 106 deletions app/client/src/modules/account/components/bsky/bsky.component.tsx

This file was deleted.

1 change: 0 additions & 1 deletion app/client/src/modules/account/components/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/client/src/modules/account/index.ts

This file was deleted.

96 changes: 12 additions & 84 deletions app/client/src/modules/admin/admin.component.tsx
Original file line number Diff line number Diff line change
@@ -1,91 +1,19 @@
import React, { FormEvent, useCallback, useEffect, useState } from "react";
import { useAdmin, useApi } from "shared/hooks";
import { Account } from "shared/types";
import { TokensComponent } from "modules/admin/tokens.component";
import React, { useEffect } from "react";
import { useAccount } from "shared/hooks";
import { useNavigate } from "react-router-dom";

export const AdminComponent: React.FC = () => {
const { getList, remove, add, update, account } = useAdmin();
const { getVersion } = useApi();

const [adminList, setAdminList] = useState<Account[]>([]);
const [accountList, setAccountList] = useState<Account[]>([]);
const [version, setVersion] = useState<string>();

const $reloadList = () =>
getList().then(({ data }) => setAdminList(data.adminList));
const { isLogged, setAsAdmin } = useAccount();
let navigate = useNavigate();

useEffect(() => {
$reloadList();
getVersion().then(({ version }) => setVersion(version));
account.getList().then(({ data }) => setAccountList(data.accountList));
}, []);

const removeAdmin = (email) => () => {
remove(email).then(() => $reloadList());
};

const onSubmit = useCallback(async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();

const data = new FormData(event.target as unknown as HTMLFormElement);
const email = data.get("email") as string;

if (!email) return;

add(email).then(() => $reloadList());
}, []);

const $update = () => {
update().then(({ status }) => {
if (status === 200)
//TODO is updating!
setTimeout(() => {
window.location.reload();
}, 10_000);
});
};
if (isLogged === null) return;
if (!isLogged) return navigate("/login");

if (!adminList.length) return <div>Loading...</div>;
setAsAdmin()
.then(() => navigate("/"))
.catch(() => navigate("/"));
}, [isLogged, setAsAdmin]);

return (
<div>
<h1>Admin</h1>
<div>
{adminList.map((user) => (
<div key={user.accountId}>
{user.email} - {user.username}
<button onClick={removeAdmin(user.email)}>delete</button>
</div>
))}
<br />
<form onSubmit={onSubmit}>
<input name="email" placeholder="email" />
<button>add admin</button>
</form>
</div>
<br />
<hr />
<h3>Update</h3>
<button onClick={$update}>Update</button>
<br />
<b>{version}</b>
<br />
<TokensComponent />
<h1>Accounts</h1>
<div>
<div>Accounts: ({accountList.length})</div>
{accountList.map((user) => (
<div key={user.accountId}>
<label title={user.email}>
{user.email.substring(0, 1)}***@***
{user.email.substring(user.email.length - 1, user.email.length)}
</label>
- {user.username}
</div>
))}
</div>
<br />
<br />
</div>
);
return <></>;
};
64 changes: 0 additions & 64 deletions app/client/src/modules/admin/tokens.component.tsx

This file was deleted.

Loading

0 comments on commit c35bdd4

Please sign in to comment.