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

View File

@ -1,3 +1,5 @@
import 'dart:html';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart'; import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/accounts.dart'; import 'package:softplayer_web/api/grpc/accounts.dart';
@ -25,7 +27,11 @@ class _SignInFormState extends State<SignInForm> {
final password = passwordCtrl.text; final password = passwordCtrl.text;
widget.accountsGrpc widget.accountsGrpc
.signIn(username, "", password) .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) { .catchError((e) {
GrpcError error = e; GrpcError error = e;
String msg; String msg;

View File

@ -1,3 +1,5 @@
import 'dart:html';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart'; import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/accounts.dart'; import 'package:softplayer_web/api/grpc/accounts.dart';
@ -32,7 +34,12 @@ class _SignUpFormState extends State<SignUpForm> {
final email = emailCtrl.text; final email = emailCtrl.text;
widget.accountsGrpc widget.accountsGrpc
.signUp(username, email, password) .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) { .catchError((e) {
GrpcError error = e; GrpcError error = e;
String msg; String msg;