git clone https://github.com/AlstonChan/Netflix-Clone.git
Then type cd Netflix-Clone
.
npm install
You may also install firebase-tools
so you can use Firebase auth emulators later,
npm install -g firebase-tools
-
Firstly, go to firebase, you should see this page. Click the top right Sign in button if you haven't sign in yet and click Get started button.
-
Next, click Add project and enter a project name you desired, then proceed to create your Firebase project.
-
Below is your firebase console, create a web app and register a name.
-
Create a
.env.local
file in the root directory (which is where your package.json file lies), and paste the following code into the file. Fill in your Firebase web app details accordingly, using.env.local
file to save these Firebase details enable you not to copy and paste the details whenever you need to access it.# Firebase Client NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY= NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN= NEXT_PUBLIC_FIREBASE_PROJECT_ID= NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET= NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID= NEXT_PUBLIC_FIREBASE_APP_ID= NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID= NEXT_PUBLIC_FIREBASE_DATABASE_URL=
-
Go to your Firebase console, select the project and navigate to
Authentication
section. Click get started and enableEmail/Password
&Google
auth, this app will use these two providers to authenticate user. -
This step is optional but is recommended, which is setting up a Firebase emulator. The emulators is built to accurately mimic the behaviors of Firebase services, so you can use Firebase auth locally and do not need to connect to Firebase cloud. To start the emulators, first copy the following code into
.env.local
.# set to true when using Firebase auth emulator NEXT_PUBLIC_USE_FIREBASE_AUTH_EMULATOR=false NEXT_PUBLIC_USE_FIREBASE_FIRESTORE_EMULATOR=false NEXT_PUBLIC_USE_FIREBASE_STORAGE_EMULATOR=false
-
Go to your text editior, in my case, I am using Visual Studio Code. Login to the Firebase CLI using the following command, You will be redirected to your browser to login.
firebase login
-
After you have successfully login to the Firebase CLI, enter this command to initialize your firebase project to this application.
firebase init
-
You will be greeted with a big FIREBASE word and you will be asked the following question:
-
Are you ready to proceed? Response: type
y
-
Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices. Response: select
Firestore
,Storage
andEmulators
by pressing space. Use arrow key to navigate your option up and down. After you have selected these three options, pressEnter
. -
Select a default Firebase project for this directory: (Use arrow keys) Response: Use a existing project and select the Firebase project that you just initialize. Press
Enter
to proceed. -
What file should be used for Firestore Rules? Response: press
Enter
; Use the defaultfirestore.rules
-
File firestore.rules already exists. Do you want to overwrite it with the Firestore Rules from the Firebase Console? Response: type
n
-
What file should be used for Firestore indexes? Response: press
Enter
; Use the defaultfirestore.indexes.json
-
File firestore.indexes.json already exists. Do you want to overwrite it with the Firestore Indexes from the Firebase Console? Response: type
n
-
What file should be used for Storage Rules? Response: press
Enter
; Use the defaultstorage.rules
-
File storage.rules already exists. Overwrite? Response: type
n
-
Which Firebase emulators do you want to set up? Press Space to select emulators, then Enter to confirm your choices. Response: select
Firestore Emulator
,Storage Emulator
andAuthentication Emulator
by pressing space. Use arrow key to navigate your option up and down. After you have selected these three options, pressEnter
. -
Which port do you want to use for the auth emulator? Response: press
Enter
; Use the default port9099
-
Which port do you want to use for the firestore emulator? Response: press
Enter
; Use the default port8080
-
Which port do you want to use for the storage emulator? Response: press
Enter
; Use the default port9199
-
Would you like to enable the Emulator UI? Response: type
y
-
Which port do you want to use for the Emulator UI (leave empty to use any available port)? Response: press
Enter
or type4060
-
Would you like to download the emulators now? Response: type
y
-
Note: You might not meet the same questions as listed in the order above, I might missed some questions.
You need movies data to populate your page, so go to The Movie Database (TMDB) and copy your api key to .env.local
. If you did not have an account, create one and fill in the form to request an api key, so you can use the api key to fetch data to your page.
MOVIE_DB_API_KEY=
FETCH_KEY=CabtUaWSst3xez8FjgSbGyqmy
Your .env.local
file should look like this if you follow the previous step correctly, and it should have value filled in. Except if you have planned not to use Firebase auth emulators, you are safe to ignore emulator related environment variable. Lastly, add NEXT_PUBLIC_CRYPTO_JS_NONCE=z3TWomYY
to the last line of your .env.local
for crypto-js
to encrypt the session data.
# Firebase Client
NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=
NEXT_PUBLIC_FIREBASE_DATABASE_URL=
# set to true when using Firebase auth emulator
NEXT_PUBLIC_USE_FIREBASE_AUTH_EMULATOR=false
NEXT_PUBLIC_USE_FIREBASE_FIRESTORE_EMULATOR=false
NEXT_PUBLIC_USE_FIREBASE_STORAGE_EMULATOR=false
MOVIE_DB_API_KEY=
FETCH_KEY=CabtUaWSst3xez8FjgSbGyqmy
# For crypto-js aes nonce
NEXT_PUBLIC_CRYPTO_JS_NONCE=z3TWomYY
Open up your terminal, and run the development server,
npm run dev
Open http://localhost:3000 with your browser to see the result.
To run the Firebase auth emulator, run
npm run emulators
Open http://localhost:4060 to view the emulator UI
This sitemap roughly shows how the app should work, and all the route of the app. NOTE that the link in the footer have no functions, because all link links to help.netflix.com, which isn't part of this project.
I have use a Dotenv Vault services to store the my .env
file as .env
file SHOULD NOT be commit and push to a repository, I figured that the dotenv vault is a great place to store such file. You could and should delete this file if you plan on using your own vault to store the .env
file or you simply wanted a remove a needless file.
Deploy to Vercel or Netlify. Remember to setup the environment variables for the app to function correctly.