Get token

This commit is contained in:
Nikolai Rodionov 2024-04-05 17:57:46 +02:00
parent 45a52d5410
commit 350cf9d4c3
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
4 changed files with 28 additions and 9 deletions

View File

@ -19,7 +19,7 @@ ENV PATH="$FLUTTER_SDK/bin:$FLUTTER_SDK/bin/cache/dart-sdk/bin:${PATH}"
RUN mkdir $APP
COPY . $APP
WORKDIR $APP
RUN flutter build web --web-renderer html
RUN flutter build web
# once heare the app will be compiled and ready to deploy

View File

@ -3,6 +3,14 @@ import 'package:grpc/grpc_web.dart';
import 'package:softplayer_dart_proto/accounts/accounts_v1.pbgrpc.dart';
import 'package:softplayer_dart_proto/main.dart';
class AccountLocalData {
AccountLocalData({
required this.uuid,
required this.token,
});
String uuid;
String token;
}
class AccountsGrpc {
final GrpcWebClientChannel channel;
late AccountsClient accountsStub;
@ -14,7 +22,7 @@ class AccountsGrpc {
accountsStub = AccountsClient(channel);
}
Future<String> signIn(String username, String email, String password) async {
Future<AccountLocalData> signIn(String username, String email, String password) async {
final request = AccountWithPassword(
data: AccountData(
name: username,
@ -25,14 +33,13 @@ class AccountsGrpc {
));
try {
final response = await accountsStub.signIn(request);
print("$response");
return "1";
return AccountLocalData(uuid: response.id.id, token: response.token);
} catch (e) {
rethrow;
}
}
Future<String> signUp(String username, String email, String password) async {
Future<AccountLocalData> signUp(String username, String email, String password) async {
final request = AccountWithPassword(
data: AccountData(
name: username,
@ -43,8 +50,7 @@ class AccountsGrpc {
));
try {
final response = await accountsStub.signUp(request);
print("$response");
return "1";
return AccountLocalData(uuid: response.id.id, token: response.token);
} catch (e) {
rethrow;
}

View File

@ -1,3 +1,5 @@
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/accounts.dart';
@ -25,7 +27,11 @@ class _SignInFormState extends State<SignInForm> {
final password = passwordCtrl.text;
widget.accountsGrpc
.signIn(username, "", password)
.then((value) => null)
.then((rs) {
window.localStorage["token"] = rs.token;
window.localStorage["uuid"] = rs.uuid;
Navigator.of(context, rootNavigator: true).pop();
})
.catchError((e) {
GrpcError error = e;
String msg;

View File

@ -1,3 +1,5 @@
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/accounts.dart';
@ -32,7 +34,12 @@ class _SignUpFormState extends State<SignUpForm> {
final email = emailCtrl.text;
widget.accountsGrpc
.signUp(username, email, password)
.then((value) => null)
.then((rs) {
window.localStorage["token"] = rs.token;
window.localStorage["uuid"] = rs.uuid;
Navigator.of(context, rootNavigator: true).pop();
})
.catchError((e) {
GrpcError error = e;
String msg;