-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User sign up #205
Closed
CSharpTeoMan911
wants to merge
23
commits into
marvelai-org:develop
from
CSharpTeoMan911:user-sign-up
Closed
User sign up #205
CSharpTeoMan911
wants to merge
23
commits into
marvelai-org:develop
from
CSharpTeoMan911:user-sign-up
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…LOPERS TO NAME THEIR FIREBASE PROJECT INDEPENDENTLY
…S THE FIREBASE DEPLOYMENT MODE
…NMENTS * MODIFIED THE NodeJS API STRUCTURE TO FACILITATE THE FIRESTORE ADMIN SIGN-IN IN BOTH DEVELOPEMNT ENVIRONMENTS AND PRODUCTION ENVIRONMENTS
…RUCTURE * UPDATED THE 'sample.dev' FILE TO INCLUDE THE `NEXT_PUBLIC_FIREBASE_DEPLOYMENT_MODE` WHICH POINTS IN WHICH TYPE OF DEPLOYMENT MODE THE FIREBASE APP IS DEPLOYED (development OR production) USING THE VALUES 'prod' or 'dev' * FINISHED THE SIGN UP FUNCTION INTEGRATION (TESTED IN CONCATENATION WITH THE MARVEL AI BACKEND)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The application was updated to facilitate the Sign-up functionality in both the development environment and the production environment. This change involved a challenge, and to be more specific it involved the CORS(Cross-Origin Resource Sharing) policy. This challenge was caused by the fact that in both the production environment and development environment, the Google Functions were served at a different origin (URL) than the web application (development e.g. Web app: https://localhost:2000 , Production: https://localhost:5001) (production e.g. Web app: https://web-app.com, Production: https://googlefunctions.com/function-name). To combat this issue the main entry point API structure of the Google Functions within the index.js file had to be re-implemented, as well as re-implementing the function calls within the frontend by switching to API requests made with Axios (e.g. GET, PUT, POST, DELETE).
Loom feature showcase: https://www.loom.com/share/672132200cf345b4b1821e0551ce0b0d?sid=c9faeb58-0e54-4873-8fe6-49b6cef3cf75
Related Issue
CORS(Cross-Origin Resource Sharing) policy does not allow the main app to call the Google Functions backend.
Type of Change
Please select the type(s) of change that apply and delete those that do not.
Proposed Solution
index.js (NodeJS)
In order to facilitate CORS, the application's API served within the index.js file had to be modified by importing the Express routing API, importing the cors library, creating an Express API instance, and passing as an option to the Express API instance cors with the option to allow cross-origin requests. The Google Functions are served as a singleton function, which serves the formerly individually served Google Functions as sub-functions which in turned are served through a CRUD Rest API interface. Each of these sub-functions are served at the endpoints in the format [GOOGLE FUNCTION URL]/[FUNCTION NAME]. For the application to be able to serve the Firestore database in production mode, the app will check if it is either in development environment or in production environment, and subsequently, if the app is in production environment it will load the Firebase API key from a file when the app is initialised.
userController.js (NodeJS)
The error handling was changed form using HttpsError to using an object that notifes the frontend if an error occured, due to the fact that the API structure had been changed. Another change is that the function is not served as an Firebase onCall event due to the fact that the calls are managed by Express.
marvelAIController.js (NodeJS)
The error handling was changed form using HttpsError to using an object that notifes the frontend if an error occured, due to the fact that the API structure had been changed. Another change is that the function is not served as an Firebase onCall event due to the fact that the calls are managed by Express.
signUp.js (ReactJS)
The function backend is now called using Axios and by passing URLs for the API functions using a function utility called functions_urls() that returns the functions URLs for either the development environment or production environment respectively.
createChatSession.js (ReactJS)
The function backend is now called using Axios and by passing URLs for the API functions using a function utility called functions_urls() that returns the functions URLs for either the development environment or production environment respectively.
sendMessage.js (ReactJS)
The function backend is now called using Axios and by passing URLs for the API functions using a function utility called functions_urls() that returns the functions URLs for either the development environment or production environment respectively.
sample.env
The sample.env file was modified to include two fields and these are: NEXT_PUBLIC_GOOGLE_CLOUD_FUNCTIONS_URL and NEXT_PUBLIC_FIREBASE_DEPLOYMENT_MODE. NEXT_PUBLIC_GOOGLE_CLOUD_FUNCTIONS_URL variable stores the URL of the cloud function. NEXT_PUBLIC_FIREBASE_DEPLOYMENT_MODE variable stores the information that specifies if the app is deployed in production or development environment using the values 'dev' and 'prod', respectively.
functions.js (ReactJS)
The file functions.js is an utility file that stores constants that contain the URLs for the Google Functions of the application's backend. These URLs are divided into 2 categories, production URLs and development URLs.
google_functions_url_selector.js (ReactJS)
The file google_functions_url_selector.js contains an utility function that through a ternary operator is determining if the application is development or production environment by verifying the value of the environment variable that is holding this value and returns the collection of URLs that are holding the Google Functions for the production environment or development environment respectively.
How to Test
The test of this feature can be viewed on this Loom link.
Unit Tests
The unit test involved incremental changes and output validation using conditional statements in relation with different situations.
Documentation Updates
Indicate whether documentation needs to be updated due to this PR.
If yes, describe what documentation updates are needed and link to the relevant documentation.
Checklist
Additional Information
Add any other information that might be useful for the reviewers.