diff --git a/android/app/build.gradle b/android/app/build.gradle index ed1f7b4..3ecfc63 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: "com.android.application" +apply plugin: "com.google.gms.google-services" import com.android.build.OutputFile diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..be05874 --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,47 @@ +{ + "project_info": { + "project_number": "836000423008", + "project_id": "unilab-1", + "storage_bucket": "unilab-1.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:836000423008:android:16eb8491d1954f00def705", + "android_client_info": { + "package_name": "com.browses3" + } + }, + "oauth_client": [ + { + "client_id": "836000423008-ad4pat0937g9buk08svsqo8f704m863g.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.browses3", + "certificate_hash": "622d2ff10752290e552a9b81b4540078f152dee4" + } + }, + { + "client_id": "836000423008-gk2g4i27gr34si5qh9t8o9euf46n8p78.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyCjPEOluTX1mqpU8KbYSSeSj5pLcM0lDEA" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "836000423008-gk2g4i27gr34si5qh9t8o9euf46n8p78.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index c9bc539..9cab232 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -27,6 +27,7 @@ buildscript { classpath("de.undercouch:gradle-download-task:5.0.1") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files + classpath("com.google.gms:google-services:4.3.12") } } diff --git a/package-lock.json b/package-lock.json index a1c4847..6243219 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,10 @@ "@react-native-firebase/firestore": "^15.1.1", "@react-navigation/native": "^6.0.10", "@react-navigation/native-stack": "^6.6.2", + "aws-sdk": "^2.1166.0", "react": "18.0.0", "react-native": "0.69.1", + "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-safe-area-context": "^4.3.1", "react-native-screens": "^3.14.0" }, @@ -5021,6 +5023,62 @@ "node": ">= 4.5.0" } }, + "node_modules/aws-sdk": { + "version": "2.1166.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1166.0.tgz", + "integrity": "sha512-9CJQpMtIv2sxvwYTcMCfuCGU8t5qEppnvmo0uFFOm+1Q1uEv5sPg95wQH3Gfj4Mmv4FKWFofgTLksn0u2pDxsw==", + "dependencies": { + "buffer": "4.9.2", + "events": "1.1.1", + "ieee754": "1.1.13", + "jmespath": "0.16.0", + "querystring": "0.2.0", + "sax": "1.2.1", + "url": "0.10.3", + "uuid": "8.0.0", + "xml2js": "0.4.19" + }, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/aws-sdk/node_modules/buffer": { + "version": "4.9.2", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz", + "integrity": "sha512-xq+q3SRMOxGivLhBNaUdC64hDTQwejJ+H0T/NB1XMtTVEwNTrfFF3gAxiyW0Bu/xWEGhjVKgUcMhCrUy2+uCWg==", + "dependencies": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4", + "isarray": "^1.0.0" + } + }, + "node_modules/aws-sdk/node_modules/ieee754": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + }, + "node_modules/aws-sdk/node_modules/sax": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", + "integrity": "sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA==" + }, + "node_modules/aws-sdk/node_modules/uuid": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz", + "integrity": "sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/aws-sdk/node_modules/xml2js": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", + "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~9.0.1" + } + }, "node_modules/babel-core": { "version": "7.0.0-bridge.0", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", @@ -6972,6 +7030,14 @@ "node": ">=6" } }, + "node_modules/events": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", + "integrity": "sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw==", + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/exec-sh": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.6.tgz", @@ -10161,6 +10227,14 @@ "jetify": "bin/jetify" } }, + "node_modules/jmespath": { + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz", + "integrity": "sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/joi": { "version": "17.6.0", "resolved": "https://registry.npmjs.org/joi/-/joi-17.6.0.tgz", @@ -12594,7 +12668,6 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "dev": true, "dependencies": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -12604,8 +12677,7 @@ "node_modules/prop-types/node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "node_modules/psl": { "version": "1.8.0", @@ -12648,6 +12720,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/querystring": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", + "integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==", + "deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.", + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -12746,6 +12827,26 @@ "resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz", "integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g==" }, + "node_modules/react-native-iphone-x-helper": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", + "integrity": "sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==", + "peerDependencies": { + "react-native": ">=0.42.0" + } + }, + "node_modules/react-native-keyboard-aware-scroll-view": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.9.5.tgz", + "integrity": "sha512-XwfRn+T/qBH9WjTWIBiJD2hPWg0yJvtaEw6RtPCa5/PYHabzBaWxYBOl0usXN/368BL1XktnZPh8C2lmTpOREA==", + "dependencies": { + "prop-types": "^15.6.2", + "react-native-iphone-x-helper": "^1.0.3" + }, + "peerDependencies": { + "react-native": ">=0.48.4" + } + }, "node_modules/react-native-safe-area-context": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz", @@ -15022,6 +15123,20 @@ "integrity": "sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==", "deprecated": "Please see https://github.com/lydell/urix#deprecated" }, + "node_modules/url": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz", + "integrity": "sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ==", + "dependencies": { + "punycode": "1.3.2", + "querystring": "0.2.0" + } + }, + "node_modules/url/node_modules/punycode": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", + "integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==" + }, "node_modules/use": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", @@ -19084,6 +19199,58 @@ "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" }, + "aws-sdk": { + "version": "2.1166.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1166.0.tgz", + "integrity": "sha512-9CJQpMtIv2sxvwYTcMCfuCGU8t5qEppnvmo0uFFOm+1Q1uEv5sPg95wQH3Gfj4Mmv4FKWFofgTLksn0u2pDxsw==", + "requires": { + "buffer": "4.9.2", + "events": "1.1.1", + "ieee754": "1.1.13", + "jmespath": "0.16.0", + "querystring": "0.2.0", + "sax": "1.2.1", + "url": "0.10.3", + "uuid": "8.0.0", + "xml2js": "0.4.19" + }, + "dependencies": { + "buffer": { + "version": "4.9.2", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz", + "integrity": "sha512-xq+q3SRMOxGivLhBNaUdC64hDTQwejJ+H0T/NB1XMtTVEwNTrfFF3gAxiyW0Bu/xWEGhjVKgUcMhCrUy2+uCWg==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4", + "isarray": "^1.0.0" + } + }, + "ieee754": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + }, + "sax": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", + "integrity": "sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA==" + }, + "uuid": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz", + "integrity": "sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==" + }, + "xml2js": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", + "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~9.0.1" + } + } + } + }, "babel-core": { "version": "7.0.0-bridge.0", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", @@ -20548,6 +20715,11 @@ "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" }, + "events": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", + "integrity": "sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw==" + }, "exec-sh": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.6.tgz", @@ -22913,6 +23085,11 @@ "resolved": "https://registry.npmjs.org/jetifier/-/jetifier-1.6.8.tgz", "integrity": "sha512-3Zi16h6L5tXDRQJTb221cnRoVG9/9OvreLdLU2/ZjRv/GILL+2Cemt0IKvkowwkDpvouAU1DQPOJ7qaiHeIdrw==" }, + "jmespath": { + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz", + "integrity": "sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==" + }, "joi": { "version": "17.6.0", "resolved": "https://registry.npmjs.org/joi/-/joi-17.6.0.tgz", @@ -24812,7 +24989,6 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "dev": true, "requires": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -24822,8 +24998,7 @@ "react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" } } }, @@ -24859,6 +25034,11 @@ "strict-uri-encode": "^2.0.0" } }, + "querystring": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", + "integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==" + }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -24952,6 +25132,21 @@ "resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz", "integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g==" }, + "react-native-iphone-x-helper": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", + "integrity": "sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==", + "requires": {} + }, + "react-native-keyboard-aware-scroll-view": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.9.5.tgz", + "integrity": "sha512-XwfRn+T/qBH9WjTWIBiJD2hPWg0yJvtaEw6RtPCa5/PYHabzBaWxYBOl0usXN/368BL1XktnZPh8C2lmTpOREA==", + "requires": { + "prop-types": "^15.6.2", + "react-native-iphone-x-helper": "^1.0.3" + } + }, "react-native-safe-area-context": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz", @@ -26720,6 +26915,22 @@ "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", "integrity": "sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==" }, + "url": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz", + "integrity": "sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ==", + "requires": { + "punycode": "1.3.2", + "querystring": "0.2.0" + }, + "dependencies": { + "punycode": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", + "integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==" + } + } + }, "use": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", diff --git a/package.json b/package.json index 6951758..3aa1258 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,10 @@ "@react-native-firebase/firestore": "^15.1.1", "@react-navigation/native": "^6.0.10", "@react-navigation/native-stack": "^6.6.2", + "aws-sdk": "^2.1166.0", "react": "18.0.0", "react-native": "0.69.1", + "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-safe-area-context": "^4.3.1", "react-native-screens": "^3.14.0" }, diff --git a/src/Navigation.js b/src/Navigation.js index 781445d..f461c44 100644 --- a/src/Navigation.js +++ b/src/Navigation.js @@ -1,18 +1,64 @@ -import React from 'react'; -import { NavigationContainer } from '@react-navigation/native'; -import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import React, {useEffect} from 'react'; +import {Text, Pressable} from 'react-native'; +import { + NavigationContainer, + useNavigationContainerRef, +} from '@react-navigation/native'; +import {createNativeStackNavigator} from '@react-navigation/native-stack'; import SignIn from './screens/SignIn'; +import useLoggedIn from './hooks/useLoggedIn'; +import SignUp from './screens/SignUp'; +import Buckets from './screens/Buckets'; +import Settings from './screens/Settings'; const Stack = createNativeStackNavigator(); const Navigation = () => { + const [isInitializing, user] = useLoggedIn(); + + console.log('[user]', user); + + if (isInitializing) { + return Loading...; + } + return ( - - + + + + {!!user ? ( + + ({ + title: 'S3 Buckets', + headerRight: () => ( + navigation.navigate('Settings')}> + + + ), + })} + /> + + + ) : null} - ) -} + ); +}; -export default Navigation; \ No newline at end of file +export default Navigation; diff --git a/src/hooks/useLoggedIn.js b/src/hooks/useLoggedIn.js new file mode 100644 index 0000000..a0e5b34 --- /dev/null +++ b/src/hooks/useLoggedIn.js @@ -0,0 +1,24 @@ +import {useState, useCallback, useEffect} from 'react'; +import auth from '@react-native-firebase/auth'; + +const useLoggedIn = () => { + const [isInit, setIsInit] = useState(true); + const [user, setUser] = useState(null); + + const onChange = useCallback( + user => { + setUser(user); + setIsInit(false); + }, + [setUser, setIsInit], + ); + + useEffect(() => { + const unsubscribe = auth().onAuthStateChanged(onChange); + return unsubscribe; + }, []); + + return [isInit, user]; +}; + +export default useLoggedIn; diff --git a/src/hooks/useLogin.js b/src/hooks/useLogin.js new file mode 100644 index 0000000..378b35c --- /dev/null +++ b/src/hooks/useLogin.js @@ -0,0 +1,21 @@ +import {useCallback} from 'react'; +import {ToastAndroid} from 'react-native'; +import auth from '@react-native-firebase/auth'; + +const useLogin = () => { + const logIn = useCallback((user, pass) => { + return auth() + .signInWithEmailAndPassword(user, pass) + .then(() => { + ToastAndroid.show('Successfully logged in', ToastAndroid.SHORT); + }) + .catch(e => { + ToastAndroid.show('Invalid username or password', ToastAndroid.SHORT); + throw e; + }); + }, []); + + return logIn; +}; + +export default useLogin; diff --git a/src/hooks/useLogout.js b/src/hooks/useLogout.js new file mode 100644 index 0000000..e052d58 --- /dev/null +++ b/src/hooks/useLogout.js @@ -0,0 +1,17 @@ +import {useCallback} from 'react'; +import {ToastAndroid} from 'react-native'; +import auth from '@react-native-firebase/auth'; + +const useLogout = () => { + const logOut = useCallback(() => { + return auth() + .signOut() + .then(() => { + ToastAndroid.show('Signed out', ToastAndroid.SHORT); + }); + }, []); + + return logOut; +}; + +export default useLogout; diff --git a/src/hooks/useSignup.js b/src/hooks/useSignup.js new file mode 100644 index 0000000..f9c8484 --- /dev/null +++ b/src/hooks/useSignup.js @@ -0,0 +1,28 @@ +import {useCallback} from 'react'; +import {ToastAndroid} from 'react-native'; +import auth from '@react-native-firebase/auth'; + +const useSignup = () => { + const signUp = useCallback((user, pass) => { + return auth() + .createUserWithEmailAndPassword(user, pass) + .then(() => { + ToastAndroid.show('Successfully registered!', ToastAndroid.SHORT); + }) + .catch(e => { + if (e.code == 'auth/email-already-in-use') { + ToastAndroid.show('Email already in use', ToastAndroid.SHORT); + } else if (e.code == 'auth/invalid-email') { + ToastAndroid.show('Invalid email address', ToastAndroid.SHORT); + } else { + ToastAndroid.show('Failed to sign up', ToastAndroid.SHORT); + } + + throw e; + }); + }, []); + + return signUp; +}; + +export default useSignup; diff --git a/src/screens/Buckets.js b/src/screens/Buckets.js new file mode 100644 index 0000000..e89a72f --- /dev/null +++ b/src/screens/Buckets.js @@ -0,0 +1,10 @@ +import React from 'react'; +import {StyleSheet, View, Text, ScrollView} from 'react-native'; + +const Buckets = () => { + return ( + Signed in!!! + ) +} + +export default Buckets; \ No newline at end of file diff --git a/src/screens/Settings.js b/src/screens/Settings.js new file mode 100644 index 0000000..690b22f --- /dev/null +++ b/src/screens/Settings.js @@ -0,0 +1,47 @@ +import React, {useCallback} from 'react'; +import {StyleSheet, View, Text, Button, TextInput} from 'react-native'; +import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'; +import useLogout from '../hooks/useLogout'; +import {useNavigation} from '@react-navigation/native'; + +const Settings = () => { + const logOut = useLogout(); + const navigation = useNavigation(); + + const onLogout = useCallback(() => { + logOut().then(() => { + navigation.reset({index: 0, routes: [{name: 'SignIn'}]}); + }); + }, [logOut]); + + return ( + + +