How can i check if a user is logged in?
Maybe this will help: https://github.com/appwrite/appwrite/discussions/3938#discussioncomment-3746725
like that?
try {
account.get();
} catch(error) {
print("not logged in");
}```
Yep! You can also add the language to enable syntax highlighting
i actually did haha
Oh sorry. Dart highlighting doesn't work on mobile 😑
to logout i need to use account.deleteSessions()right?
but then it will still show my logged in screen
Depends on how you build your app...
if this would be right it would show the not logged in screen
class LoggedIn extends StatelessWidget {
@override
Widget build(BuildContext context) {
try {
account().get();
return Home(title: 'Outfytr');
} catch(error) {
return NotLoggedIn();
}
}
}
class Home extends StatefulWidget {
final String title;
Home({required this.title});
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Align(
alignment: Alignment.topRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
onPressed: () {
account().deleteSessions();
},
child: Text("Logout"),
),
],
),
),
);
}
}
You need to handle state and update the app accordingly...
and how (sorry im new to flutter)
It might be good to find some additional tutorials or so for flutter then
i've watched some, but i dont get the mistake
In order to refresh the UI, you need to update state
So it should be a statusful widget?
Yes
but the authenticated checker still does not work
code:
class LoggedIn extends StatefulWidget {
@override
_LoggedInStatus createState() => _LoggedInStatus();
}
class _LoggedInStatus extends State<LoggedIn> {
@override
Widget build(BuildContext context) {
try {
account().get();
return NotLoggedIn();
} catch(error) {
return Home();
}
}
}
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Outfytr"),
),
body: Align(
alignment: Alignment.topRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
onPressed: () {
account().deleteSessions();
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => NotLoggedIn()),
);
},
child: Text("Logout"),
),
Text(User.name().toString())
],
),
),
);
}
}```
I think you need some more tutorials and practice with state fundamentals in flutter
thats also a fix, somehow xD
after some working I think the error that i get is not on the widget site, i think, that it's the way I check the logged in. Do you know the fix?
error: Error: AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401)
If an exception is thrown they aren't logged in....so then you need to update state based on that
Recommended threads
- redirect_uri errors on flutter client
Hi all, I'm using the flutter client for my app to do appwrite auth and use the JWTs to send to my backend. When I try to sign in with SSO, I get this: https:/...
- Problem with getting rows from related t...
Hi, I migrated the Appwrite SDK to 1.8.0 and the package in my Flutter app to version ^20.3.2. I noticed one thing is different. Previously, when I got a JSON r...
- client.ping() does not appear to work.
After upgrading to 1.8.0, I ran the `starter_for_flutter` and tested the ping. It failed with a "Server Error". I tried this again on my production instance (1...