diff --git a/data_connect/dataconnect/connector/mutations.gql b/data_connect/dataconnect/connector/mutations.gql index 154aa98..82a899a 100644 --- a/data_connect/dataconnect/connector/mutations.gql +++ b/data_connect/dataconnect/connector/mutations.gql @@ -1,9 +1,8 @@ -mutation UpsertUser($username: String!, $name: String!) @auth(level: USER) { +mutation UpsertUser($username: String!) @auth(level: USER) { user_upsert( data: { id_expr: "auth.uid" username: $username - name: $name } ) } diff --git a/data_connect/dataconnect/connector/queries.gql b/data_connect/dataconnect/connector/queries.gql index d16ea2a..f0904ba 100644 --- a/data_connect/dataconnect/connector/queries.gql +++ b/data_connect/dataconnect/connector/queries.gql @@ -114,7 +114,6 @@ query GetCurrentUser @auth(level: USER) { user(key: { id_expr: "auth.uid" }) { id username - name reviews: reviews_on_user { id rating diff --git a/data_connect/dataconnect/schema/schema.gql b/data_connect/dataconnect/schema/schema.gql index 7558ee2..1eecf54 100644 --- a/data_connect/dataconnect/schema/schema.gql +++ b/data_connect/dataconnect/schema/schema.gql @@ -46,7 +46,6 @@ type User @table { id: String! @col(name: "user_auth") username: String! @col(name: "username", dataType: "varchar(50)") - name: String! # The following are generated from the @ref in the Review table # reviews_on_user # movies_via_Review diff --git a/data_connect/lib/login.dart b/data_connect/lib/login.dart index fbce525..91685bb 100644 --- a/data_connect/lib/login.dart +++ b/data_connect/lib/login.dart @@ -29,7 +29,7 @@ class _LoginState extends State { await MoviesConnector.instance.getCurrentUser().execute(); if (isLoggedIn.data.user == null) { await MoviesConnector.instance - .upsertUser(username: _username.text, name: _username.text) + .upsertUser(username: _username.text) .execute(); } if (mounted) { diff --git a/data_connect/lib/movies_connector/get_current_user.dart b/data_connect/lib/movies_connector/get_current_user.dart index c6639d5..6a2ae55 100644 --- a/data_connect/lib/movies_connector/get_current_user.dart +++ b/data_connect/lib/movies_connector/get_current_user.dart @@ -24,8 +24,6 @@ class GetCurrentUserUser { String username; - String name; - List reviews; List favoriteMovies; @@ -33,7 +31,6 @@ class GetCurrentUserUser { GetCurrentUserUser.fromJson(dynamic json) : id = nativeFromJson(json['id']), username = nativeFromJson(json['username']), - name = nativeFromJson(json['name']), reviews = (json['reviews'] as List) .map((e) => GetCurrentUserUserReviews.fromJson(e)) .toList(), @@ -48,8 +45,6 @@ class GetCurrentUserUser { json['username'] = nativeToJson(username); - json['name'] = nativeToJson(name); - json['reviews'] = reviews.map((e) => e.toJson()).toList(); json['favoriteMovies'] = favoriteMovies.map((e) => e.toJson()).toList(); @@ -60,7 +55,6 @@ class GetCurrentUserUser { GetCurrentUserUser({ required this.id, required this.username, - required this.name, required this.reviews, required this.favoriteMovies, }); diff --git a/data_connect/lib/movies_connector/movies.dart b/data_connect/lib/movies_connector/movies.dart index 63df0d5..eae8dfc 100644 --- a/data_connect/lib/movies_connector/movies.dart +++ b/data_connect/lib/movies_connector/movies.dart @@ -50,12 +50,10 @@ String enumSerializer(Enum e) { class MoviesConnector { UpsertUserVariablesBuilder upsertUser({ required String username, - required String name, }) { return UpsertUserVariablesBuilder( dataConnect, username: username, - name: name, ); } diff --git a/data_connect/lib/movies_connector/upsert_user.dart b/data_connect/lib/movies_connector/upsert_user.dart index d4c8986..1bdc55f 100644 --- a/data_connect/lib/movies_connector/upsert_user.dart +++ b/data_connect/lib/movies_connector/upsert_user.dart @@ -2,14 +2,12 @@ part of movies_connector; class UpsertUserVariablesBuilder { String username; - String name; FirebaseDataConnect _dataConnect; UpsertUserVariablesBuilder( this._dataConnect, { required String this.username, - required String this.name, }); Deserializer dataDeserializer = (dynamic json) => UpsertUserData.fromJson(jsonDecode(json)); @@ -22,7 +20,6 @@ class UpsertUserVariablesBuilder { MutationRef ref() { UpsertUserVariables vars = UpsertUserVariables( username: username, - name: name, ); return _dataConnect.mutation( @@ -71,26 +68,20 @@ class UpsertUserData { class UpsertUserVariables { String username; - String name; - @Deprecated( 'fromJson is deprecated for Variable classes as they are no longer required for deserialization.') UpsertUserVariables.fromJson(Map json) - : username = nativeFromJson(json['username']), - name = nativeFromJson(json['name']) {} + : username = nativeFromJson(json['username']) {} Map toJson() { Map json = {}; json['username'] = nativeToJson(username); - json['name'] = nativeToJson(name); - return json; } UpsertUserVariables({ required this.username, - required this.name, }); } diff --git a/data_connect/lib/profile.dart b/data_connect/lib/profile.dart index 321e1d0..01e356a 100644 --- a/data_connect/lib/profile.dart +++ b/data_connect/lib/profile.dart @@ -20,15 +20,16 @@ class Profile extends StatelessWidget { stream: MovieState.subscribeToCurrentUser(), builder: (context, snapshot) { final res = snapshot.data; - if (res == null) { + if (res == null || res.data.user == null) { return const Center( child: CircularProgressIndicator(), ); } - final displayName = res.data.user!.name; + final displayName = + FirebaseAuth.instance.currentUser?.displayName ?? ''; final favoriteMovies = res.data.user!.favoriteMovies.map((e) => e.movie).toList(); - final reviews = res.data.user!.reviews; + final reviews = res.data.user == null ? [] : res.data.user!.reviews; return RefreshIndicator( child: SingleChildScrollView( physics: const AlwaysScrollableScrollPhysics(), @@ -40,7 +41,7 @@ class Profile extends StatelessWidget { children: [ Column( children: [ - Text('Welcome back $displayName !'), + Text('Welcome back $displayName!'), TextButton( onPressed: () async { FirebaseAuth.instance.signOut(); diff --git a/data_connect/lib/sign_up.dart b/data_connect/lib/sign_up.dart index 86dc21c..72332c0 100644 --- a/data_connect/lib/sign_up.dart +++ b/data_connect/lib/sign_up.dart @@ -1,3 +1,4 @@ +import 'package:dataconnect/movie_state.dart'; import 'package:dataconnect/movies_connector/movies.dart'; import 'package:dataconnect/widgets/auth_dialog.dart'; import 'package:firebase_auth/firebase_auth.dart'; @@ -23,9 +24,9 @@ class _SignUpState extends State { try { await FirebaseAuth.instance.createUserWithEmailAndPassword( email: _username, password: _password); - await MoviesConnector.instance - .upsertUser(username: _username, name: _name) - .execute(); + await FirebaseAuth.instance.currentUser!.updateDisplayName(_name); + await MoviesConnector.instance.upsertUser(username: _username).execute(); + MovieState.triggerUpdateFavorite(); if (mounted) { context.go('/home'); }