feat: add disable / delete funct; bump revolt-api

This commit is contained in:
Paul Makles
2022-06-10 14:32:21 +01:00
parent a5e5f3ea0b
commit abf7413066
8 changed files with 47 additions and 26 deletions

View File

@@ -177,7 +177,7 @@ export function SpecialInputModal(props: SpecialProps) {
question={"Add Friend"}
callback={(username) =>
client.api
.put(`/users/${username as ""}/friend`)
.post(`/users/friend`, { username })
.then(undefined)
}
/>

View File

@@ -3,7 +3,7 @@ import { observer } from "mobx-react-lite";
import { Client } from "revolt.js";
import { createContext } from "preact";
import { useContext, useEffect, useState } from "preact/hooks";
import { useCallback, useContext, useEffect, useState } from "preact/hooks";
import { Preloader } from "@revoltchat/ui";
@@ -29,7 +29,7 @@ export interface ClientOperations {
export const AppContext = createContext<Client>(null!);
export const StatusContext = createContext<ClientStatus>(null!);
export const LogOutContext = createContext(() => {});
export const LogOutContext = createContext((avoidReq?: boolean) => {});
type Props = {
children: Children;
@@ -42,10 +42,10 @@ export default observer(({ children }: Props) => {
const [status, setStatus] = useState(ClientStatus.LOADING);
const [loaded, setLoaded] = useState(false);
function logout() {
const logout = useCallback((avoidReq?: boolean) => {
setLoaded(false);
client.logout(false);
}
client.logout(avoidReq);
}, []);
useEffect(() => {
if (navigator.onLine) {

View File

@@ -58,7 +58,7 @@ export interface LegacySyncOptions {
export interface LegacyAuthState {
accounts: {
[key: string]: {
session: API.Session;
session: Session;
};
};
active?: string;

View File

@@ -8,7 +8,7 @@ import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface Account {
session: API.Session;
session: Session;
}
export interface Data {
@@ -82,7 +82,7 @@ export default class Auth implements Store, Persistent<Data> {
* Add a new session to the auth manager.
* @param session Session
*/
@action setSession(session: API.Session) {
@action setSession(session: Session) {
this.sessions.set(session.user_id, { session });
this.current = session.user_id;
}

View File

@@ -21,6 +21,7 @@ import { stopPropagation } from "../../../lib/stopPropagation";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
import {
ClientStatus,
LogOutContext,
StatusContext,
useClient,
} from "../../../context/revoltjs/RevoltClient";
@@ -30,6 +31,7 @@ import UserIcon from "../../../components/common/user/UserIcon";
export const Account = observer(() => {
const { openScreen, writeClipboard } = useIntermediate();
const logOut = useContext(LogOutContext);
const status = useContext(StatusContext);
const client = useClient();
@@ -207,9 +209,15 @@ export const Account = observer(() => {
"Disable your account. You won't be able to access it unless you contact support."
}
action="chevron"
onClick={() => {
//
}}>
onClick={() =>
client.api
.post("/auth/account/disable", undefined, {
headers: {
"X-MFA-Ticket": "TICKET",
},
})
.then(() => logOut(true))
}>
<Text id="app.settings.pages.account.manage.disable" />
</CategoryButton>
<CategoryButton
@@ -218,9 +226,15 @@ export const Account = observer(() => {
"Your account will be queued for deletion, a confirmation email will be sent."
}
action="chevron"
onClick={() => {
//
}}>
onClick={() =>
client.api
.post("/auth/account/delete", undefined, {
headers: {
"X-MFA-Ticket": "TICKET",
},
})
.then(() => logOut(true))
}>
<Text id="app.settings.pages.account.manage.delete" />
</CategoryButton>
<Tip>

7
src/types/revolt-api.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
// TODO: re-export from revolt-api in some way
declare type Session = {
_id: string;
token: string;
name: string;
user_id: string;
};