Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class _SignInState extends State<SignIn> {
- @override
- void initState() {
- super.initState();
- MsalMobile.create('assets/auth_config.json', authority).then((client) {
- setState(() {
- msal = client;
- });
- refreshSignedInStatus();
- });
- }
- /// Updates the signed in state
- refreshSignedInStatus() {
- msal.getSignedIn().then((loggedIn) {
- print('refreshing');
- setState(() async {
- isSignedIn = loggedIn;
- dynamic currentAccount = await handleGetAccount();
- if(isSignedIn) {
- Navigator.of(context).pushReplacement(
- MaterialPageRoute(
- builder: (context) => NavScreen(
- currentUser : currentAccount,
- ),
- ),
- );
- }
- });
- });
- }
- /// Gets the current and prior accounts.
- Future <dynamic> handleGetAccount() async {
- await msal.getAccount().then((result) {
- if (result.currentAccount != null) {
- return result.currentAccount.username;
- } else {
- print('no account found');
- return null;
- }
- }).catchError((exception) {
- if (exception is MsalMobileException) {
- logMsalMobileError(exception);
- } else {
- print('exception occurred');
- return null;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement