Skip to content

Commit

Permalink
feat!: Migrate to the Nhost v2 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
shyndman committed Jan 28, 2022
1 parent e62e0e2 commit 828ec5c
Show file tree
Hide file tree
Showing 205 changed files with 5,829 additions and 4,807 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2021 Nhost AB

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| Package | | |
|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [nhost_sdk](packages/nhost_sdk) | Dart authentication and file storage API clients | [![nhost_sdk](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_sdk.yaml/badge.svg)](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_sdk.yaml) [![nhost_sdk Pub](https://img.shields.io/pub/v/nhost_sdk)](https://pub.dev/packages/nhost_sdk) |
| [nhost_sdk](packages/nhost_sdk) | Authentication, file storage, and serverless function API clients | [![nhost_sdk](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_sdk.yaml/badge.svg)](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_sdk.yaml) [![nhost_sdk Pub](https://img.shields.io/pub/v/nhost_sdk)](https://pub.dev/packages/nhost_sdk) |
| [nhost_flutter_auth](packages/nhost_flutter_auth) | Flutter widgets for exposing Nhost Auth state to your app | [![nhost_flutter_auth](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_flutter_auth.yaml/badge.svg)](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_flutter_auth.yaml) [![nhost_flutter_auth Pub](https://img.shields.io/pub/v/nhost_flutter_auth)](https://pub.dev/packages/nhost_flutter_auth) |
| [nhost_flutter_graphql](packages/nhost_flutter_graphql) | Flutter widgets for providing Nhost GraphQL connections, for use with the [graphql_flutter](https://pub.dev/packages/graphql_flutter) package | [![nhost_flutter_graphql](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_flutter_graphql.yaml/badge.svg)](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_flutter_graphql.yaml) [![nhost_flutter_auth Pub](https://img.shields.io/pub/v/nhost_flutter_graphql)](https://pub.dev/packages/nhost_flutter_graphql) |
| [nhost_graphql_adapter](packages/nhost_graphql_adapter) | GraphQL connection setup, for use with the [graphql](https://pub.dev/packages/graphql) package | [![nhost_graphql_adapter](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_graphql_adapter.yaml/badge.svg)](https://github.com/nhost/nhost-dart/actions/workflows/test.nhost_graphql_adapter.yaml) [![nhost_graphql_adapter Pub](https://img.shields.io/pub/v/nhost_graphql_adapter)](https://pub.dev/packages/nhost_graphql_adapter) |
Expand Down
2 changes: 1 addition & 1 deletion packages/nhost_flutter_auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ making it easy to set up protected resources, and react to logins and logouts.

```yaml
dependencies:
nhost_flutter_auth: ^1.0.0
nhost_flutter_auth: ^2.0.0-beta.0
```
## 🔥 More Dart & Flutter packages from Nhost
Expand Down
2 changes: 2 additions & 0 deletions packages/nhost_flutter_auth/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const nhostUrl = 'http://localhost:1337';
26 changes: 12 additions & 14 deletions packages/nhost_flutter_auth/example/lib/navigator_2_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import 'package:flutter/material.dart';
import 'package:nhost_flutter_auth/nhost_flutter_auth.dart';
import 'package:provider/provider.dart';

import 'config.dart';
import 'simple_auth_example.dart';

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';

void main() {
configurePackages();
runApp(NavigatorExampleApp());
Expand All @@ -44,7 +42,7 @@ class _NavigatorExampleAppState extends State<NavigatorExampleApp> {
void initState() {
super.initState();
// Create a new Nhost client using your project's backend URL.
nhostClient = NhostClient(baseUrl: nhostApiUrl);
nhostClient = NhostClient(backendUrl: nhostUrl);
appState = ExampleNavigator();
}

Expand Down Expand Up @@ -132,9 +130,9 @@ class ExampleRouterDelegate extends RouterDelegate<ExampleRoutePath>
final auth = NhostAuthProvider.of(context)!;
final requestedRoutePath = navigator.requestedRoutePath;
final isLoginPageRequested = requestedRoutePath is LoginRoutePath &&
auth.authenticationState != AuthenticationState.loggedIn;
auth.authenticationState != AuthenticationState.signedIn;
final needsLogin = requestedRoutePath is ProtectedRoutePath &&
auth.authenticationState != AuthenticationState.loggedIn;
auth.authenticationState != AuthenticationState.signedIn;

return Navigator(
key: navigatorKey,
Expand Down Expand Up @@ -214,7 +212,7 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
final auth = NhostAuthProvider.of(context)!;
final isAuthenticated =
auth.authenticationState == AuthenticationState.loggedIn;
auth.authenticationState == AuthenticationState.signedIn;
final navigator = Provider.of<ExampleNavigator>(context);

final textTheme = Theme.of(context).textTheme;
Expand All @@ -240,7 +238,7 @@ class HomePage extends StatelessWidget {
),
),
ContentItem(child: Text('This content is visible to everyone.')),
if (auth.authenticationState == AuthenticationState.loggedIn)
if (auth.authenticationState == AuthenticationState.signedIn)
ContentItem(
child: Text(
'This additional content is only visible to authenticated '
Expand All @@ -256,17 +254,17 @@ class HomePage extends StatelessWidget {
child: Text('Admin Page (Protected)'),
),
SizedBox(width: 8),
if (auth.authenticationState == AuthenticationState.loggedOut)
if (auth.authenticationState == AuthenticationState.signedOut)
ElevatedButton(
onPressed: () {
navigator.requestRoutePath(LoginRoutePath());
},
child: Text('Login'),
),
if (auth.authenticationState == AuthenticationState.loggedIn)
if (auth.authenticationState == AuthenticationState.signedIn)
ElevatedButton(
onPressed: () {
auth.logout();
auth.signOut();
},
child: Text('Logout'),
),
Expand Down Expand Up @@ -349,18 +347,18 @@ class AppFrame extends StatelessWidget {
appBar: AppBar(
title: Text('Nhost Navigator 2.0 Example'),
actions: [
if (auth.authenticationState == AuthenticationState.loggedOut)
if (auth.authenticationState == AuthenticationState.signedOut)
IconButton(
icon: Icon(Icons.login),
onPressed: () {
navigator.requestRoutePath(LoginRoutePath());
},
),
if (auth.authenticationState == AuthenticationState.loggedIn)
if (auth.authenticationState == AuthenticationState.signedIn)
IconButton(
icon: Icon(Icons.logout),
onPressed: () {
auth.logout();
auth.signOut();
navigator.requestRoutePath(HomeRoutePath());
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
/// Failure redirect URL: `nhost-example://oauth.login.failure`.
library oauth_providers_example;

import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:nhost_flutter_auth/nhost_flutter_auth.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher;
import 'package:app_links/app_links.dart';

import 'config.dart';
import 'simple_auth_example.dart';

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';
const nhostGithubLoginUrl = '$nhostApiUrl/auth/providers/github/';
const nhostGithubLoginUrl = '$nhostUrl/v1/auth/providers/github/';

const loginSuccessHost = 'oauth.login.success';
const loginFailureHost = 'oauth.login.failure';
Expand All @@ -43,13 +43,13 @@ class _OAuthExampleState extends State<OAuthExample> {
super.initState();

// Create a new Nhost client using your project's backend URL.
nhostClient = NhostClient(baseUrl: nhostApiUrl);
nhostClient = NhostClient(backendUrl: nhostUrl);

appLinks = AppLinks(
onAppLink: (uri, stringUri) async {
if (uri.host == loginSuccessHost) {
// ignore: unawaited_futures
nhostClient.auth.completeOAuthProviderLogin(uri);
nhostClient.auth.completeOAuthProviderSignIn(uri);
}
await url_launcher.closeWebView();
},
Expand Down Expand Up @@ -88,7 +88,7 @@ class ExampleProtectedScreen extends StatelessWidget {
Widget widget;

switch (auth.authenticationState) {
case AuthenticationState.loggedIn:
case AuthenticationState.signedIn:
widget = LoggedInUserDetails();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import 'package:flutter/material.dart';
import 'package:nhost_flutter_auth/nhost_flutter_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'config.dart';
import 'simple_auth_example.dart';

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';

void main() {
runApp(PersistentAuthExample());
}
Expand All @@ -37,7 +35,7 @@ class _PersistentAuthExampleState extends State<PersistentAuthExample> {
super.initState();
// Create a new Nhost client using your project's backend URL.
nhostClient = NhostClient(
baseUrl: nhostApiUrl,
backendUrl: nhostUrl,
// Instruct the client to store tokens using shared preferences.
authStore: SharedPreferencesAuthStore(),
);
Expand Down
13 changes: 6 additions & 7 deletions packages/nhost_flutter_auth/example/lib/simple_auth_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ library simple_auth_example;
import 'package:flutter/material.dart';
import 'package:nhost_flutter_auth/nhost_flutter_auth.dart';

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';
import 'config.dart';

void main() {
runApp(SimpleAuthExample());
Expand All @@ -24,7 +23,7 @@ class _SimpleAuthExampleState extends State<SimpleAuthExample> {
void initState() {
super.initState();
// Create a new Nhost client using your project's backend URL.
nhostClient = NhostClient(baseUrl: nhostApiUrl);
nhostClient = NhostClient(backendUrl: nhostUrl);
}

@override
Expand Down Expand Up @@ -57,10 +56,10 @@ class ExampleProtectedScreen extends StatelessWidget {
final auth = NhostAuthProvider.of(context)!;
Widget widget;
switch (auth.authenticationState) {
case AuthenticationState.loggedIn:
case AuthenticationState.signedIn:
widget = LoggedInUserDetails();
break;
case AuthenticationState.loggedOut:
case AuthenticationState.signedOut:
widget = LoginForm();
break;
default:
Expand Down Expand Up @@ -105,7 +104,7 @@ class _LoginFormState extends State<LoginForm> {
final auth = NhostAuthProvider.of(context)!;

try {
await auth.login(
await auth.signIn(
email: emailController.text, password: passwordController.text);
} on ApiException {
ScaffoldMessenger.of(context).showSnackBar(
Expand Down Expand Up @@ -196,7 +195,7 @@ class LoggedInUserDetails extends StatelessWidget {
rowSpacing,
ElevatedButton(
onPressed: () {
auth.logout();
auth.signOut();
},
child: Text('Logout'),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void main() {
expect(buildCount, 1);

// Emulate an auth state change, then pump the engine
mockAuth.triggerStateChange(AuthenticationState.loggedOut);
mockAuth.triggerStateChange(AuthenticationState.signedOut);
await tester.pump();

// The state change should result in a second build
Expand Down
2 changes: 1 addition & 1 deletion packages/nhost_flutter_graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to work with [Nhost](https://nhost.io).

```yaml
dependencies:
nhost_flutter_graphql: ^1.0.0
nhost_flutter_graphql: ^2.0.0-beta.0
```
## 🔥 More Dart & Flutter packages from Nhost
Expand Down
2 changes: 2 additions & 0 deletions packages/nhost_flutter_graphql/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const nhostUrl = 'http://localhost:1337';
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:nhost_flutter_graphql/nhost_flutter_graphql.dart';

// IMPORTANT: Fill in these values with the Backend and GraphQL URL found on
// your Nhost project page.

const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';
const nhostGraphQLUrl = 'https://hasura-5e69d1d7.nhost.app/v1/graphql';
import 'config.dart';

/// Client used to authenticate GraphQL requests
final nhostClient = NhostClient(baseUrl: nhostApiUrl);
final nhostClient = NhostClient(backendUrl: nhostUrl);

void main() {
runApp(SimpleGqlExample());
Expand All @@ -29,7 +25,6 @@ class SimpleGqlExample extends StatelessWidget {
// to `graphql_flutter` widgets in its subtree.
return NhostGraphQLProvider(
nhostClient: nhostClient,
gqlEndpointUrl: nhostGraphQLUrl,
child: MaterialApp(
title: 'Nhost.io Simple Flutter GraphQL Example',
debugShowCheckedModeBanner: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:nhost_flutter_auth/nhost_flutter_auth.dart';
import 'package:nhost_flutter_graphql/nhost_flutter_graphql.dart';

// Fill in these values with the Backend and GraphQL URL found on your Nhost
// project page.

const nhostApiUrl = 'https://backend-5e69d1d7.nhost.app';
const nhostGraphQLUrl = 'https://hasura-5e69d1d7.nhost.app/v1/graphql';
import 'config.dart';

void main() {
runApp(TodosQuickStartExample());
Expand All @@ -26,8 +22,7 @@ class TodosQuickStartExample extends StatelessWidget {
// The NhostGraphQLProvider automatically provides connection information
// to `graphql_flutter` widgets in its subtree.
return NhostGraphQLProvider(
nhostClient: NhostClient(baseUrl: nhostApiUrl),
gqlEndpointUrl: nhostGraphQLUrl,
nhostClient: NhostClient(backendUrl: nhostUrl),
child: MaterialApp(
title: 'Nhost.io Todos Quick Start',
debugShowCheckedModeBanner: false,
Expand All @@ -48,10 +43,10 @@ class App extends StatelessWidget {

Widget widget;
switch (auth.authenticationState) {
case AuthenticationState.loggedIn:
case AuthenticationState.signedIn:
widget = TodosPage();
break;
case AuthenticationState.loggedOut:
case AuthenticationState.signedOut:
widget = LoginPage();
break;
default:
Expand Down Expand Up @@ -219,7 +214,10 @@ class TodoList extends StatelessWidget {

return ListView(
children: [
for (final todo in todos) TodoTile(todo: todo),
for (final todo in todos)
if (!todo.isCompleted) TodoTile(todo: todo),
for (final todo in todos)
if (todo.isCompleted) TodoTile(todo: todo),
],
);
}
Expand Down Expand Up @@ -268,7 +266,7 @@ class TodoListActions extends StatelessWidget {
children: [
TextButton(
onPressed: () {
auth.logout();
auth.signOut();
},
child: Text('Logout'),
),
Expand Down Expand Up @@ -323,8 +321,8 @@ class _LoginPageState extends State<LoginPage> {
@override
void initState() {
super.initState();
emailController = TextEditingController();
passwordController = TextEditingController();
emailController = TextEditingController(text: '[email protected]');
passwordController = TextEditingController(text: 'password-1');
}

@override
Expand All @@ -338,7 +336,7 @@ class _LoginPageState extends State<LoginPage> {
final auth = NhostAuthProvider.of(context)!;

try {
await auth.login(
await auth.signIn(
email: emailController.text, password: passwordController.text);
} on ApiException {
ScaffoldMessenger.of(context).showSnackBar(
Expand Down
Loading

0 comments on commit 828ec5c

Please sign in to comment.