2024-08-27 09:28:24 -07:00
|
|
|
import "./App.css";
|
2024-08-27 09:39:28 -07:00
|
|
|
import "bootstrap/dist/css/bootstrap.min.css";
|
2024-08-27 10:48:49 -07:00
|
|
|
import * as base64 from "base-64";
|
2024-08-26 16:07:43 -07:00
|
|
|
|
2024-08-27 09:28:24 -07:00
|
|
|
//import MailboxList from "./Mailbox";
|
|
|
|
import AuthModal from "./AuthModal";
|
2024-08-27 09:39:28 -07:00
|
|
|
import React, { useEffect, useState } from "react";
|
2024-08-27 09:28:24 -07:00
|
|
|
|
|
|
|
interface IAuth {
|
2024-08-27 11:11:54 -07:00
|
|
|
email: string;
|
2024-08-27 09:39:28 -07:00
|
|
|
password: string;
|
2024-08-27 08:23:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const App = () => {
|
2024-08-27 09:39:28 -07:00
|
|
|
const [state, setInternalState] = useState<IAuth | null>(null);
|
|
|
|
|
2024-08-27 11:11:54 -07:00
|
|
|
// When the user provides credentials
|
|
|
|
const onLogin = (email: string, password: string) => {
|
|
|
|
// Store the provided credentials for now
|
|
|
|
const auth = {email: email, password: password}
|
|
|
|
setInternalState(auth);
|
|
|
|
localStorage.setItem("auth", JSON.stringify(auth));
|
|
|
|
doLogin(auth);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make the request to get system metadata
|
|
|
|
const doLogin = (auth: IAuth) => {
|
|
|
|
const domain = auth.email.split("@")[1];
|
2024-08-27 10:48:49 -07:00
|
|
|
const well_known_url = "https://" + domain + "/.well-known/jmap"
|
|
|
|
let headers = new Headers();
|
2024-08-27 11:11:54 -07:00
|
|
|
headers.append("Authorization", "Basic " + base64.encode(auth.email + ":" + auth.password));
|
2024-08-27 10:48:49 -07:00
|
|
|
fetch(well_known_url, {
|
|
|
|
method: "GET",
|
|
|
|
headers: headers,
|
|
|
|
})
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => console.log(data))
|
|
|
|
.catch(error => console.error(error));
|
2024-08-27 10:18:24 -07:00
|
|
|
};
|
2024-08-27 09:39:28 -07:00
|
|
|
|
2024-08-27 11:11:54 -07:00
|
|
|
const loadAuth = () => {
|
|
|
|
const data = localStorage.getItem("auth");
|
|
|
|
if (!data) return;
|
|
|
|
const auth = JSON.parse(data);
|
|
|
|
setInternalState(auth);
|
|
|
|
doLogin(auth);
|
2024-08-27 09:39:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadAuth();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="App">
|
2024-08-27 11:11:54 -07:00
|
|
|
{state ? <p>{state.email}</p> : <AuthModal onLogin={onLogin}></AuthModal>}
|
2024-08-27 09:39:28 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2024-07-31 20:58:46 -07:00
|
|
|
|
|
|
|
export default App;
|