commit bbacdce6b36a19cf0aca5d5ea58d263f61db46da
parent d543cf84f5a7845660ff0413359161bdd4c43acc
Author: MTRNord <mtrnord1@gmail.com>
Date: Mon, 24 Jan 2022 19:44:05 +0100
Fix various bugs on the login page
Diffstat:
5 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/helpers/matrix_client.ts b/helpers/matrix_client.ts
@@ -141,7 +141,11 @@ export default class MatrixClient {
}
async getOpenidToken(): Promise<string> {
- const data = await this.fetchJson(`${this.userId!.slice(this.userId!.indexOf(":") + 1)}/_matrix/client/r0/user/${this.userId}/openid/request_token`, { method: "POST" });
+ const data = await this.fetchJson(`${this.serverUrl}/r0/user/${this.userId}/openid/request_token`, {
+ method: "POST",
+ body: "{}",
+ headers: { Authorization: `Bearer ${this.accessToken}` },
+ });
return data.access_token;
}
diff --git a/helpers/ss-well-known.ts b/helpers/ss-well-known.ts
@@ -21,7 +21,6 @@ export default class ServerOpenID {
// Step 3 of server resolving
const resp = await fetch(`https://${server}/.well-known/matrix/server`, { method: "GET" });
if (resp.status === 200) {
- console.log("Step 3");
const data: SSWellKnownContent = await resp.json();
@@ -31,20 +30,16 @@ export default class ServerOpenID {
const possibleDelegatedServerParts = delegatedServer.split(this.splitRegex);
if (possibleDelegatedServerParts.length === 1) {
// Step 3.1
- console.log("Step 3.1");
if (isIP(possibleDelegatedServerParts[0]) > 0) {
return { address: `${delegatedServer}:8448`, host_header: delegatedServer };
} else {
// Step 3.3.1
- console.log("Step 3.3.1");
const srv = await this.resolver.resolveSrv(`_matrix._tcp.${possibleDelegatedServerParts[0]}`);
if (srv.length > 0) {
// Step 3.3.3
- console.log("Step 3.3.3");
if (isIP(srv[0].name) > 0) {
return { address: `${srv[0].name}:${srv[0].port}`, host_header: delegatedServer };
} else {
- console.log("Step 3.3.2");
// Step 3.3.2
const result_v4 = await this.resolver.resolve(srv[0].name, "A");
if (result_v4.length > 0) {
@@ -59,7 +54,6 @@ export default class ServerOpenID {
}
} else {
// Step 3.4
- console.log("Step 3.4");
const result_v4 = await this.resolver.resolve(possibleDelegatedServerParts[0], "A");
if (result_v4.length > 0) {
return { address: `${result_v4[0]}:8448`, host_header: delegatedServer };
@@ -76,11 +70,9 @@ export default class ServerOpenID {
} else if (possibleDelegatedServerParts.length === 5) {
// Step 3.1
if (isIP(possibleDelegatedServerParts[1]) > 0) {
- console.log("Step 3.1");
return { address: delegatedServer, host_header: delegatedServer };
} else {
// Step 3.2
- console.log("Step 3.2");
const result_v4 = await this.resolver.resolve(possibleDelegatedServerParts[1], "A");
if (result_v4.length > 0) {
return { address: `${result_v4[0]}:${possibleDelegatedServerParts[4]}`, host_header: delegatedServer };
@@ -106,16 +98,13 @@ export default class ServerOpenID {
// Step 1 of Server Discovery
if (possibleServerParts.length === 1) {
if (isIP(possibleServerParts[0]) > 0) {
- console.log("Step 1a");
return { address: `${server}:8448`, host_header: server };
}
} else if (possibleServerParts.length === 5) {
if (isIP(possibleServerParts[1]) > 0) {
- console.log("Step 1b");
return { address: server, host_header: server };
} else {
// Step 2 of Server Discovery.
- console.log("Step 2");
const result_v4 = await this.resolver.resolve(possibleServerParts[1], "A");
if (result_v4.length > 0) {
return { address: `${result_v4[0]}:${possibleServerParts[4]}`, host_header: server };
@@ -140,7 +129,6 @@ export default class ServerOpenID {
// Step 4
const srv = await this.resolver.resolveSrv(`_matrix._tcp.${server}`);
if (srv.length > 0) {
- console.log("Step 4");
if (isIP(srv[0].name) > 0) {
return { address: `${srv[0].name}:${srv[0].port}`, host_header: server };
} else {
@@ -156,7 +144,6 @@ export default class ServerOpenID {
throw new Error("Unable to resolve the server");
}
} else {
- console.log("Step 5");
// Step 5
const result_v4 = await this.resolver.resolve(server, "A");
if (result_v4.length > 0) {
diff --git a/pages/api/directory.tsx b/pages/api/directory.tsx
@@ -53,7 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
user_id: string;
user_room: string;
access_token: string;
- } = req.body;
+ } = JSON.parse(req.body);
if (await (new ServerOpenID().verify(data.user_id, data.access_token))) {
const db_data = {
_id: data.user_id,
@@ -77,7 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const data: {
user_id: string;
access_token: string;
- } = req.body;
+ } = JSON.parse(req.body);
if (await (new ServerOpenID().verify(data.user_id, data.access_token))) {
try {
const db_data = await db.get(data.user_id);
diff --git a/pages/login.tsx b/pages/login.tsx
@@ -29,6 +29,8 @@ class Login extends PureComponent<Props, State> {
this.state = {
showServerField: false,
generateProfile: false,
+ mxid: "",
+ password: "",
serverUrl: constMatrixArtServer,
serverFieldsDisplay: 'none',
serverFieldsOpacity: 0,
@@ -74,6 +76,7 @@ class Login extends PureComponent<Props, State> {
} else if (this.state.showServerField && !serverUrl.endsWith("/_matrix/client") && !serverUrl.endsWith("/_matrix/client/")) {
serverUrl = serverUrl + "/_matrix/client";
}
+ console.log(serverUrl);
if (this.state.mxid && this.state.password) {
this.setState({
diff --git a/pages/submit.tsx b/pages/submit.tsx
@@ -115,7 +115,7 @@ class Submit extends PureComponent<Props, State> {
<Dropzone accept='image/*' onDropAccepted={this.onDrop} onDropRejected={this.onDropError}>
{({ getRootProps, getInputProps }) => (
<section className="flex flex-col">
- <div className="dark:bg-[#fefefe]/[.25] bg-[#14181E]/[.25] min-h-[11.5rem] min-w-[39.5rem] flex-[1] flex flex-col items-center justify-center p-5 border-2 rounded-sm border-[#eeeeee] border-dashed outline-none focus:border-[#2196f3] duration-[24ms] transition" {...getRootProps()}>
+ <div className="dark:bg-[#fefefe]/[.25] bg-[#14181E]/[.25] min-h-[11.5rem] min-w-[39.5rem] flex-[1] flex flex-col items-center justify-center p-5 border-2 rounded-sm border-[#eeeeee] border-dashed outline-none hover:border-[#2196f3] duration-[24ms] transition" {...getRootProps()}>
<input {...getInputProps()} />
<p className="text-base text-gray-900 dark:text-gray-200">Drag 'n' drop some images here, or click to select images</p>
</div>