diff --git a/Containerfile b/Containerfile index ec3a91d..b7e28ec 100644 --- a/Containerfile +++ b/Containerfile @@ -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 diff --git a/lib/api/grpc/accounts.dart b/lib/api/grpc/accounts.dart index 8bf223f..4659d94 100644 --- a/lib/api/grpc/accounts.dart +++ b/lib/api/grpc/accounts.dart @@ -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 signIn(String username, String email, String password) async { + Future 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 signUp(String username, String email, String password) async { + Future 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; } diff --git a/lib/components/sign_in_form.dart b/lib/components/sign_in_form.dart index 7e2bc6a..ddc7dd3 100644 --- a/lib/components/sign_in_form.dart +++ b/lib/components/sign_in_form.dart @@ -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 { 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; diff --git a/lib/components/sign_up_form.dart b/lib/components/sign_up_form.dart index 8772779..e3023ec 100644 --- a/lib/components/sign_up_form.dart +++ b/lib/components/sign_up_form.dart @@ -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 { 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;