This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace JWTProtectedAPI.ViewModels | |
{ | |
public class SignInData | |
{ | |
public string Email { get; set; } | |
public string Password { get; set; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace JWTProtectedAPI.ViewModels | |
{ | |
public class UserProfile | |
{ | |
public string Email { get; set; } | |
public string Username { get; set; } | |
public string PhoneNumber { get; set; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Rest of the SignIn() and ValidateUserCredentials() methods | |
[HttpGet] | |
//We add this annotation to tell the framework this is service/route requires Authorization Claims i.e JWT | |
[Authorize] | |
[Route("my-profile")] | |
public async Task<ActionResult<UserProfile>> GetMyProfile() | |
{ | |
try | |
{ | |
//Todo add your business validation here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidgetWithAppBarWrapper extends StatelessWidget { | |
final Widget Function(BuildContext) builder; | |
const WidgetWithAppBarWrapper({Key? key, required this.builder}) | |
: super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Builder(builder: (context) => builder(context)), | |
bottomNavigationBar: PersistantBottomAppBar()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/cubit/user_authentication_cubit.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/repositories/api/fake_account_api_service.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/routes/routes.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/exceptions/access_token_exception.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/exceptions/business_exception.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/exceptions/refresh_token_exception.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/models/account/renew_access_token.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/models/account/sign_in.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/models/session/authentication_data.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
part of 'user_authentication_cubit.dart'; | |
@immutable | |
abstract class UserAuthenticationState { | |
const UserAuthenticationState(); | |
} | |
class UserAuthenticationInitial extends UserAuthenticationState { | |
const UserAuthenticationInitial(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tutorial_flutter_minimalist_authentication | |
description: A new Flutter project. | |
# The following line prevents the package from being accidentally published to | |
# pub.dev using `flutter pub publish`. This is preferred for private packages. | |
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |
# The following defines the version and build number for your application. | |
# A version number is three numbers separated by dots, like 1.2.43 | |
# followed by an optional build number separated by a +. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/cubit/user_authentication_cubit.dart'; | |
import 'package:tutorial_flutter_minimalist_authentication/models/session/authentication_data.dart'; | |
class ProtectedWidget extends StatelessWidget { | |
final Widget Function(BuildContext, AuthenticationData) onAuthenticated; | |
final Widget onUnauthenticatedChild; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class AccountRepository { | |
Future<AuthenticationData> signIn({required SignIn signIn}); | |
Future<bool> verifyToken({required String accessToken}); | |
Future<AuthenticationData> renewAccessToken( | |
{required RenewAccessToken renewAccessToken}); | |
} |