Save username/password instead of tokens

The tokens never worked. I don't know what i'm doing wrong but fluffychat basically just logs in and never tries to save anything. Im not sure how im meant to do this.
This commit is contained in:
Brandon Presley 2023-12-30 11:17:21 +13:00
parent 1cd8ba41ae
commit f229c0371b

View File

@ -44,10 +44,9 @@ class _MyHomePageState extends State<MyHomePage> {
final prefs = await SharedPreferences.getInstance();
final homeserver = prefs.getString("homeserver");
final username = prefs.getString("username");
final accessToken = prefs.getString("accessToken");
final refreshToken = prefs.getString("refreshToken");
final password = prefs.getString("password");
if (homeserver == null || username == null || accessToken == null) return;
if (homeserver == null || username == null || password == null) return;
if (!mounted) return;
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
@ -55,7 +54,9 @@ class _MyHomePageState extends State<MyHomePage> {
try {
await client.checkHomeserver(Uri.parse(homeserver));
await client.login(LoginType.mLoginToken, token: accessToken);
await client.login(LoginType.mLoginPassword,
password: password,
identifier: AuthenticationUserIdentifier(user: username));
provider.setClient(client);
setState(() {
showRooms = true;
@ -76,6 +77,19 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
if (errorMessage.isNotEmpty)
return Column(
children: [
ErrorWidget(errorMessage),
ElevatedButton(
onPressed: () {
setState(() {
errorMessage = "";
});
},
child: const Text("Clear"))
],
);
if (showRooms)
return const RoomsPage();
else