Skip to content

Commit

Permalink
feat: new type connection to proxy (#10)
Browse files Browse the repository at this point in the history
* feat: new type connection to proxy (#9)

* refactor: change type variable .env

* feat: connection to the proxy via HTTP & check new endpoints

* [ci skip] chore(release): 0.0.7

---------

Co-authored-by: Antonio Donis <[email protected]>
  • Loading branch information
SantiagoGaonaC and shoriwe authored Sep 24, 2023
1 parent 20bdff1 commit 2e2d68d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1 +1 @@
API_LOGIN_URL = http://IP-LOCALHOST-OR-API:PORT
API_URL = "http://IP-LOCALHOST-OR-API:PORT"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.7 (2023-09-24)


### Features

* new type connection to proxy ([#9](https://github.com/hawks-atlanta/frontend-flutter/issues/9)) ([3154ee5](https://github.com/hawks-atlanta/frontend-flutter/commit/3154ee52d6f5d46c0086a0ba24749b86d5712954))

### 0.0.6 (2023-08-30)

### 0.0.5 (2023-08-30)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ This will expose `0.0.0.0:8080` with a running REST API service on your machine.

- Then configure the **`.env`** file in the root of this repository with the IP of your machine on your local network (so your Android phone or emulator can reach the service)

*Note: check whether it's **HTTP** or HTTPS with the service's port address provided by the proxy; it should be HTTP for it to work in Flutter.*

```shell
echo "API_LOGIN_URL = http://IP_OF_YOUR_COMPUTER:8080" > .env
echo 'API_URL="http://IP_OF_YOUR_COMPUTER:PORT"' > .env
```

- Install flutter dependencies with:
Expand Down
17 changes: 9 additions & 8 deletions lib/features/auth/domain/entities/user.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
class User {
final String uuid;
final String username;
final int statusCode;
final String message;
//final String uuid;
//final String username;
//final int statusCode;
//final String? message;
final String token;

//TODO?: add required
User({
required this.uuid,
required this.username,
required this.statusCode,
required this.message,
//required this.uuid,
//required this.username,
//required this.statusCode,
//required this.message,
required this.token,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import 'package:login_mobile/features/auth/infrastructure/infrastructure.dart';
class AuthDataSourceImpl extends AuthDataSource {
final dio = Dio(BaseOptions(
baseUrl: Enviroment.apiURL,

));

@override
Future<User> checkAuthStatus(String token) async {
try {
final response = await dio.get('/check-status',
options: Options(
headers: {
'Authorization': 'Bearer $token'
})
);
final response = await dio.post('/challenge',
options: Options(headers: {'Authorization': 'Bearer $token'}));
final user = UserMapper.userJsonToEntity(response.data);
return user;
} on DioException catch (e) {
Expand All @@ -35,15 +32,14 @@ class AuthDataSourceImpl extends AuthDataSource {
try {
final responde = await dio
.post('/login', data: {'username': username, 'password': password});

final user = UserMapper.userJsonToEntity(responde.data);
return user;
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw CustomError(e.response?.data['message'] ?? 'Credentials wrong');
}
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError( 'Review your internet connection');
throw CustomError('Review your internet connection');
}
throw Exception();
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions lib/features/auth/infrastructure/mappers/user_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class UserMapper {

static User userJsonToEntity(Map<String, dynamic> json) {
return User(
uuid: json['uuid'],
username: json['username'],
statusCode: json['statusCode'],
message: json['message'],
token: json['token']
//uuid: json['uuid'],
//username: json['username'],
//statusCode: json['statusCode'],
//message: json['message'],
token: json['jwt']
);
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"git-semver-tags": "^4.1.1",
"standard-version": "^9.5.0"
},
"version": "0.0.6"
"version": "0.0.7"
}

0 comments on commit 2e2d68d

Please sign in to comment.