feat: Implemented log in, sign up and sign out

This commit is contained in:
Fándly Gergő 2022-06-30 23:26:18 +03:00
parent 3e78eff210
commit 7bf0d428b8
14 changed files with 659 additions and 25 deletions

View File

@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply plugin: "com.google.gms.google-services"
import com.android.build.OutputFile

View File

@ -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"
}

View File

@ -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")
}
}

223
package-lock.json generated
View File

@ -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",

View File

@ -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"
},

View File

@ -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 <Text>Loading...</Text>;
}
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="SignIn" component={SignIn} />
<Stack.Navigator initialRouteName={!!user ? 'Buckets' : 'SignIn'}>
<Stack.Screen
name="SignIn"
component={SignIn}
options={{title: 'Sign In'}}
/>
<Stack.Screen
name="SignUp"
component={SignUp}
options={{title: 'Sign Up'}}
/>
{!!user ? (
<React.Fragment>
<Stack.Screen
name="Buckets"
component={Buckets}
options={({navigation}) => ({
title: 'S3 Buckets',
headerRight: () => (
<Pressable onPress={() => navigation.navigate('Settings')}>
<Text style={{fontSize: 24, color: '#000000'}}></Text>
</Pressable>
),
})}
/>
<Stack.Screen
name="Settings"
component={Settings}
options={{title: 'Settings'}}
/>
</React.Fragment>
) : null}
</Stack.Navigator>
</NavigationContainer>
)
}
);
};
export default Navigation;
export default Navigation;

24
src/hooks/useLoggedIn.js Normal file
View File

@ -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;

21
src/hooks/useLogin.js Normal file
View File

@ -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;

17
src/hooks/useLogout.js Normal file
View File

@ -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;

28
src/hooks/useSignup.js Normal file
View File

@ -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;

10
src/screens/Buckets.js Normal file
View File

@ -0,0 +1,10 @@
import React from 'react';
import {StyleSheet, View, Text, ScrollView} from 'react-native';
const Buckets = () => {
return (
<Text>Signed in!!!</Text>
)
}
export default Buckets;

47
src/screens/Settings.js Normal file
View File

@ -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 (
<KeyboardAwareScrollView style={styles.root}>
<View style={styles.button}>
<Button onPress={onLogout} title="Sign out" />
</View>
</KeyboardAwareScrollView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: '#FEFEFE',
padding: 10,
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
borderRadius: 3,
backgroundColor: '#DDDDDD',
color: '#000000',
},
button: {
margin: 12,
marginBottom: 32,
},
});
export default Settings;

View File

@ -1,19 +1,116 @@
import React from 'react';
import {View, Text, StyleSheet} from 'react-native';
import React, {useState, useCallback} from 'react';
import {
View,
Text,
TextInput,
Button,
Pressable,
ToastAndroid,
StyleSheet,
} from 'react-native';
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
import {useNavigation} from '@react-navigation/native';
import useLogin from '../hooks/useLogin';
const SignIn = () => {
const navigation = useNavigation();
const [email, setEmail] = useState('');
const [pass, setPass] = useState('');
const logIn = useLogin();
const onSubmit = useCallback(() => {
if (!email || !pass) {
ToastAndroid.show(
'Error! You need to provide both an email and a password',
ToastAndroid.SHORT,
);
return;
}
logIn(email, pass)
.then(() => {
console.log('asdasd');
navigation.reset({index: 0, routes: [{name: 'Buckets'}]});
})
.catch(() => {});
}, [email, pass, logIn, navigation]);
const onSignup = useCallback(() => {
navigation.navigate('SignUp');
}, []);
return (
<View style={styles.root}>
<Text>Hello!</Text>
</View>
)
}
<KeyboardAwareScrollView style={styles.root}>
<Text style={styles.title}>BrowseS3</Text>
<Text style={styles.subtitle}>Made by: Fándly Gergő-Zoltán</Text>
<Text style={styles.welcome}>Welcome! Please sign in to continue!</Text>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
autoComplete="email"
/>
<TextInput
style={styles.input}
placeholder="Password"
value={pass}
onChangeText={setPass}
autoComplete="password"
secureTextEntry
/>
<View style={styles.button}>
<Button onPress={onSubmit} title="Sign in" />
</View>
<Pressable onPress={onSignup}>
<Text style={styles.signUp}>No account? Sign up here!</Text>
</Pressable>
</KeyboardAwareScrollView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: '#FEFEFE'
}
})
backgroundColor: '#FEFEFE',
padding: 10,
},
title: {
fontSize: 32,
textAlign: 'center',
marginTop: 32,
color: '#000000',
},
subtitle: {
color: '#000000',
marginBottom: 132,
textAlign: 'right',
},
welcome: {
fontSize: 20,
color: '#000000',
marginBottom: 32,
textAlign: 'center',
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
borderRadius: 3,
backgroundColor: '#DDDDDD',
color: '#000000',
},
button: {
margin: 12,
marginBottom: 32,
},
signUp: {
color: '#CCCCCC',
fontSize: 12,
textAlign: 'center',
textDecorationLine: 'underline',
},
});
export default SignIn;
export default SignIn;

82
src/screens/SignUp.js Normal file
View File

@ -0,0 +1,82 @@
import React, {useState, useCallback} from 'react';
import {StyleSheet, View, Text, TextInput, Button} from 'react-native';
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
import useSignup from '../hooks/useSignup';
import {useNavigation} from '@react-navigation/native';
const SignUp = () => {
const [email, setEmail] = useState('');
const [pass, setPass] = useState('');
const signUp = useSignup();
const navigation = useNavigation();
const onSubmit = useCallback(() => {
if (!email || !pass) {
ToastAndroid.show(
'Error! You need to provide both an email and a password',
ToastAndroid.SHORT,
);
return;
}
signUp(email, pass)
.then(() => {
console.log('asdasd');
navigation.reset({index: 0, routes: [{name: 'Buckets'}]});
})
.catch(() => {});
}, [email, pass, signUp, navigation]);
return (
<KeyboardAwareScrollView style={styles.root}>
<Text style={styles.help}>Let's create a new user for you!</Text>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
autoComplete="email"
/>
<TextInput
style={styles.input}
placeholder="Password"
value={pass}
onChangeText={setPass}
autoComplete="password-new"
secureTextEntry
/>
<View style={styles.button}>
<Button onPress={onSubmit} title="Sign up" />
</View>
</KeyboardAwareScrollView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: '#FEFEFE',
padding: 10,
},
help: {
color: '#000000',
fontSize: 18,
textAlign: 'center',
marginBottom: 32,
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
borderRadius: 3,
backgroundColor: '#DDDDDD',
color: '#000000',
},
button: {
margin: 12,
marginBottom: 32,
},
});
export default SignUp;