Migrate to rAuth v1.

This commit is contained in:
Paul
2021-09-11 17:36:23 +01:00
parent a4138b52b0
commit 5b422b89e3
15 changed files with 116 additions and 87 deletions

View File

@@ -1,4 +1,5 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { Session } from "revolt-api/types/Auth";
import { Client } from "revolt.js";
import { Route } from "revolt.js/dist/api/routes";
@@ -15,7 +16,6 @@ import { Children } from "../../types/Preact";
import { useIntermediate } from "../intermediate/Intermediate";
import { registerEvents, setReconnectDisallowed } from "./events";
import { takeError } from "./util";
import { Session } from "revolt-api/types/Auth";
export enum ClientStatus {
INIT,
@@ -29,7 +29,9 @@ export enum ClientStatus {
}
export interface ClientOperations {
login: (data: Route<"POST", "/auth/login">["data"]) => Promise<void>;
login: (
data: Route<"POST", "/auth/session/login">["data"],
) => Promise<void>;
logout: (shouldRequest?: boolean) => Promise<void>;
loggedIn: () => boolean;
ready: () => boolean;

View File

@@ -9,7 +9,10 @@ export function takeError(error: any): string {
const type = error?.response?.data?.type;
const id = type;
if (!type) {
if (error?.response?.status === 403) {
if (
error?.response?.status === 401 ||
error?.response?.status === 403
) {
return "Unauthorized";
} else if (error && !!error.isAxiosError && !error.response) {
return "NetworkError";