#sprint-1 changed readme added token service and maked handleLogout service

This commit is contained in:
User3 2025-05-27 12:18:26 +03:00
parent 998d829da3
commit f5a75e3fdf
4 changed files with 38 additions and 39 deletions

View File

@ -1,39 +1,3 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
// Тесты в server_test.dart
// Запускать встроенными экшенами
// в apis Лежат все апи структурированно

View File

@ -4,6 +4,7 @@ import 'package:server/server.dart';
class Auth {
String lastError = '';
login(String email, String password) async {
try {
final response = await api.post(

21
lib/apis/tokens.dart Normal file
View File

@ -0,0 +1,21 @@
import 'package:dio/dio.dart';
import 'package:server/client.dart';
class Tokens {
String lastError = '';
getAccessToken() async {
try {
final response = await api.get('/collections/_authOrigins/records');
return response.data['items'][0]['id'];
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
}
final tokens = Tokens();

View File

@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:server/apis/auth.dart';
import 'package:server/apis/cart.dart';
import 'package:server/apis/shop.dart';
import 'package:server/apis/tokens.dart';
void main() {
test('Спринт 2. Авторизация', () async {
@ -72,4 +73,16 @@ void main() {
return Error();
}
});
test('Спринт 2.Логаут пользователя', () async {
try {
final currentId = await tokens.getAccessToken();
if (currentId != null) {
final response = await auth.userLogout(currentId);
return response.data;
}
} catch (e) {
print(e);
return Error();
}
});
}