Skip to content

Commit bf7dcfd

Browse files
update ionic version and some router changes
1 parent 13bc9ae commit bf7dcfd

File tree

7 files changed

+67
-79
lines changed

7 files changed

+67
-79
lines changed

package-lock.json

+19-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"version": "0.0.0",
44
"private": true,
55
"dependencies": {
6-
"@capacitor/android": "^2.0.1",
7-
"@capacitor/core": "^2.3.0",
8-
"@capacitor/ios": "^2.0.1",
6+
"@capacitor/android": "2.4.0",
7+
"@capacitor/core": "2.4.0",
8+
"@capacitor/ios": "2.4.0",
99
"@firebase/app": "^0.6.8",
1010
"@hookform/error-message": "0.0.3",
11-
"@ionic/react": "5.2.3",
12-
"@ionic/react-router": "5.2.3",
11+
"@ionic/react": "5.3.1",
12+
"@ionic/react-router": "5.3.1",
1313
"@types/react": "16.9.43",
1414
"@types/react-dom": "16.9.8",
15-
"@types/react-router": "^5.1.4",
16-
"@types/react-router-dom": "^5.1.3",
15+
"@types/react-router": "5.1.8",
16+
"@types/react-router-dom": "5.1.5",
1717
"firebase": "7.16.1",
1818
"ionicons": "5.1.2",
1919
"react": "16.13.1",

src/App.tsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import "./env";
33
import React, { Suspense } from "react";
44
import { FirebaseAppProvider, AuthCheck } from "reactfire";
55

6-
import { IonApp, IonRouterOutlet, IonLoading } from "@ionic/react";
6+
import { IonApp, IonRouterOutlet, IonLoading } from "@ionic/react";
7+
import { Route, Redirect } from "react-router-dom";
78
import { IonReactRouter } from "@ionic/react-router";
89

910
/* Core CSS required for Ionic components to work properly */
@@ -28,7 +29,6 @@ import Login from "./pages/Login";
2829
import Home from "./pages/Home";
2930

3031
import { Plugins } from "@capacitor/core";
31-
import { Route, Redirect } from "react-router";
3232
import CreateAccount from "./pages/CreateAccount";
3333
const { SplashScreen } = Plugins;
3434

@@ -38,13 +38,20 @@ SplashScreen.hide();
3838
const PublicRoutes: React.FunctionComponent = () => {
3939
return (
4040
<IonRouterOutlet>
41-
<Route exact path="/login">
42-
<Login />
43-
</Route>
44-
<Route exact path="/create-account">
45-
<CreateAccount />
41+
<Route exact path="/login" component={Login} />
42+
<Route exact path="/create-account" component={CreateAccount} />
43+
<Redirect exact path="/" to="/login" />
44+
</IonRouterOutlet>
45+
);
46+
};
47+
48+
const PrivateRoutes: React.FunctionComponent = () => {
49+
return (
50+
<IonRouterOutlet>
51+
<Route exact path="/home">
52+
<Home />
4653
</Route>
47-
<Redirect path="/" to="/login" />
54+
<Redirect exact path="/" to="/home" />
4855
</IonRouterOutlet>
4956
);
5057
};
@@ -54,13 +61,11 @@ const App: React.FunctionComponent = () => {
5461
<FirebaseAppProvider firebaseConfig={FIREBASE_CONFIG}>
5562
<IonApp>
5663
<IonReactRouter>
57-
<IonRouterOutlet>
5864
<Suspense fallback={<IonLoading isOpen={true} />}>
5965
<AuthCheck fallback={<PublicRoutes />}>
60-
<Home />
66+
<PrivateRoutes />
6167
</AuthCheck>
6268
</Suspense>
63-
</IonRouterOutlet>
6469
</IonReactRouter>
6570
</IonApp>
6671
</FirebaseAppProvider>

src/index.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import React from 'react';
1+
import React from "react";
22

3+
import ReactDOM from "react-dom";
4+
import App from "./App";
5+
import * as serviceWorker from "./serviceWorker";
36

4-
import ReactDOM from 'react-dom';
5-
import App from './App';
6-
import * as serviceWorker from './serviceWorker';
7-
8-
9-
ReactDOM.render(
10-
<App />,
11-
document.getElementById("root")
12-
);
7+
ReactDOM.render(<App />, document.getElementById("root"));
138

149
// If you want your app to work offline and load faster, you can change
1510
// unregister() to register() below. Note this comes with some pitfalls.

src/pages/CreateAccount.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ const CreateAccount: React.FunctionComponent = () => {
7474
);
7575
};
7676

77-
console.log(errors);
78-
77+
console.log(history);
7978
return (
8079
<IonPage>
8180
<IonHeader>

src/pages/Home.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import "firebase/firestore";
2525
import { FIREBASE_COLLECTION_NAME } from "../env";
2626
import AddSomethingModal, { IModalResponse } from "./AddSomethingModal";
27+
import { useHistory } from "react-router";
2728

2829
type IShowAlert = null | {
2930
header: string;
@@ -34,6 +35,7 @@ type IShowAlert = null | {
3435
const Home: React.FunctionComponent = () => {
3536
// reactfire hook to get auth information
3637
const auth = useAuth();
38+
const history = useHistory();
3739

3840
// another reactfire hook to get the firebase app
3941
const thingsRef = useFirebaseApp()
@@ -92,7 +94,14 @@ const Home: React.FunctionComponent = () => {
9294
<IonHeader>
9395
<IonToolbar color="light">
9496
<IonButtons slot="end">
95-
<IonButton onClick={() => auth.signOut()}>Logout</IonButton>
97+
<IonButton
98+
onClick={() => {
99+
auth.signOut();
100+
history.replace("/login");
101+
}}
102+
>
103+
Logout
104+
</IonButton>
96105
</IonButtons>
97106
<IonTitle>Home</IonTitle>
98107
</IonToolbar>

src/pages/Login.tsx

+9-29
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {
1414
} from "@ionic/react";
1515

1616
import { useForm, Controller } from "react-hook-form";
17-
import { ErrorMessage } from "@hookform/error-message";
1817

1918
import { useAuth } from "reactfire";
2019
import { useHistory } from "react-router";
20+
import { MyErrorDisplay } from "../components/MyErrorDisplay";
2121

2222
export interface CheckboxChangeEventDetail {
2323
value: any;
@@ -48,36 +48,16 @@ const Login: React.FunctionComponent = () => {
4848
console.log(data);
4949
try {
5050
let r = await auth.signInWithEmailAndPassword(data.email, data.password);
51-
history.replace("/")
51+
history.replace("/home");
5252
console.log(r);
5353
} catch (e) {
5454
setShowErrorAlert(e.message);
5555
}
5656
};
5757

58-
const myErrorDisplay = (elementName: string) => {
59-
return (
60-
<ErrorMessage
61-
errors={errors}
62-
name={elementName}
63-
as={
64-
<div
65-
style={{
66-
color: "red",
67-
paddingTop: 6,
68-
paddingLeft: 16,
69-
fontStyle: "italic",
70-
}}
71-
/>
72-
}
73-
/>
74-
);
75-
};
76-
77-
console.log(errors);
78-
58+
console.log(history);
7959
return (
80-
<IonPage>
60+
<IonPage>
8161
<IonHeader>
8262
<IonToolbar color="light">
8363
<IonButtons slot="start" />
@@ -95,12 +75,12 @@ const Login: React.FunctionComponent = () => {
9575
buttons={["OK"]}
9676
/>
9777

98-
<form onSubmit={handleSubmit(signIn)}>
78+
<form onSubmit={handleSubmit(signIn)}>
9979
<IonItem>
10080
<IonLabel>Email</IonLabel>
10181
<Controller
10282
render={({ onChange }) => (
103-
<IonInput type="email" onIonChange={onChange} defaultValue="" />
83+
<IonInput type="email" onIonChange={onChange} />
10484
)}
10585
control={control}
10686
defaultValue=""
@@ -115,7 +95,7 @@ const Login: React.FunctionComponent = () => {
11595
}}
11696
/>
11797
</IonItem>
118-
{myErrorDisplay("email")}
98+
<MyErrorDisplay errors={errors} elementName="email" />
11999
<IonItem>
120100
<IonLabel>Password</IonLabel>
121101
<Controller
@@ -134,15 +114,15 @@ const Login: React.FunctionComponent = () => {
134114
}}
135115
/>
136116
</IonItem>
137-
{myErrorDisplay("password")}
117+
<MyErrorDisplay errors={errors} elementName="password" />
138118
<div className="ion-padding">
139119
<IonButton expand="block" type="submit">
140120
Log In
141121
</IonButton>
142122
<IonButton
143123
expand="block"
144124
type="button"
145-
onClick={() => history.push("create-account")}
125+
onClick={() => history.push("/create-account")}
146126
>
147127
Create Account
148128
</IonButton>

0 commit comments

Comments
 (0)