Watch on YouTubePlayPlays from YouTube. Google's privacy policy (opens in a new tab) applies.
Adam explains secrets (environment variables) and why they never go on GitHub, then creates a .env.local file with the local database keys, starts the app and logs in with a test account.
What you'll learn
- What a secret (environment variable) is: a key–value pair, such as a database address or an API key.
- Why a leaked API key can cost real money.
- Deployed apps keep secrets in the host's settings, e.g. Vercel's Environment Variables.
- Never put environment files on GitHub, even in a private repository.
.env.examplelists which keys exist; you create.env.localwith the values..gitignorelists files git must never track; env files are usually in it.- Show hidden files on a Mac with Cmd-Shift-. (dot).
- Test accounts are listed in the README.
Chapters
- 00:00Why your app needs secrets
- 01:44Keep secrets off GitHub
- 03:08Finding the hidden env files
- 04:47Creating .env.local, checking .gitignore
- 06:11Filling in the database keys
- 07:47Running the app and logging in
- 00:00Well, in the previous video, we have installed Docker and we have run it.
- 00:04Does it mean that we can finally go and start the application locally?
- 00:09Well, not quite because even though we have the application and we have a code base database locally, our application still doesn't know where to look for that database.
- 00:18And the reason it doesn't know is because that is a secret.
- 00:23And the secret is important because like in general, you really don't want other people to know where to look for your database or what is the URL of your
- 00:33database. That is one example of many secrets that your application can have.
- 00:39Another example of a secret that your application can have is when you have some third-party integration.
- 00:46Let's say you're trying to build an application that has a chatbot, an AI chatbot.
- 00:50You will likely going to need either OpenAI's or Anthropic's models for this.
- 00:55So you'll need to set up a developer account in one of the in either of these companies and you'll have to generate your API key and you'll going to
- 01:06need this API key in your code base in order to have that integration running.
- 01:11And that API key is something that you're going to be charged for.
- 01:15I mean the usage under that API key is something you're going to be charged for because you'll need to have your credit card connected.
- 01:22You really want to make sure that only you or and the people you trust have access to that API key because if it ever gets leaked, anyone with an
- 01:31access to this API key can start using it in their own applications and that can cost you a lot of money.
- 01:40So we know there are secrets in the applications.
- 01:43Where do you keep them?
- 01:44Well, in the case of a deployed application like this one, if this was deployed on Vercel and you can pretend it is in Vercel, there in the project settings
- 01:55there is actually a page called environmental variables and this is where you keep secrets.
- 02:00And a secret is just an uh uh like a key value pair.
- 02:04So you have a key which is the name of the um of the of the secret and then value being like the actual thing you want to protect.
- 02:13And while it is okay for everyone else to know what kind of variables or what kind of secrets you'll you'll need to know in order for your application uh
- 02:23to to run, you really want to protect the secrets themselves.
- 02:28Uh which means that um you don't really want for these environmental variables to ever end up on GitHub or on a Git track repository that is available publicly.
- 02:39Uh it doesn't really matter if this repository is private.
- 02:42You really just don't want to have your environmental keys on GitHub under any circumstances.
- 02:49If there is just one key takeaway for you from this entire video course, well I'm not personally sure if that would be the one.
- 02:58I can imagine there are people who are going to say this is the one key takeaway.
- 03:02You really don't want to keep your application or environmental variables on GitHub.
- 03:08Uh what you want to do again is you want to have a list of the keys that you're going to need to have in order to run this application.
- 03:16And this repo has one.
- 03:18And it's stored in a special kind of file that is called .env.example.
- 03:24ENV stands for environment and example stands for example.
- 03:30So if I go if I go and open this up, it seems like our application only needs two keys and both are related to the database.
- 03:40So our application simply needs to know where to look for the database.
- 03:44And um if I go back to uh my Finder and open up the folder for this um uh for this code base, I cannot really see these files unless
- 03:56I do command shift and dot on your Mac.
- 03:59That is command shift and dot.
- 04:01Uh this is going to up all of the hidden files, so files that begin with a dot in their name, and only them then I can actually see that
- 04:09that the .env example file is also present on my Mac locally.
- 04:15Um, so what I'll want to do first of all, I wouldn't be really looking at any of this if I were a real engineer.
- 04:22I wouldn't be really looking at this through a finder.
- 04:24I would probably be looking at this and editing these files in a code editor like VS Code.
- 04:29But we have an installed one in this course, and we are not going to be doing this.
- 04:33So I'm okay with the fact that this couple of next steps are going to be a little bit awkward.
- 04:38Again, this is not really how you would want to go about this, uh, but we are going to be fine with this as well.
- 04:45Um, so I'm going to, first of all, create a copy of this file.
- 04:49So command C, command V.
- 04:51Then I'm going to remove the, uh, .example.
- 04:55This is going to create my local environment file.
- 04:58Actually, I'm going to give it a name local.
- 05:00That is a common convention.
- 05:02Um, and, um, later on we're going to ask Claude to make sure that this file this file is going is going to be git uh, git ignored, meaning, um,
- 05:13or I think it might already actually be git ignored.
- 05:16Uh, is there Yeah, there is a git ignore file.
- 05:18What what is a git ignore file?
- 05:19Actually, let me open this up, um, in text edit.
- 05:23Um, so git ignore file is, as the name suggests, it's just a list of either file names or file types, file extensions that should be excluded from being git
- 05:34tracked, and therefore they are never going to be included in your GitHub repository.
- 05:40And it is a very common thing for red repositories to have the this git ignore file, and for these files to also have the any all sorts of environmental
- 05:50files being git ignored.
- 05:52So, uh, what it means is that even though I have this file here, it's not really a risk, uh, for this file to be ever committed, uh, to and
- 06:00and like pushed to the main remote GitHub repository, okay?
- 06:05Uh, so that is that.
- 06:06So, let me open up this git this environmental local file.
- 06:11Also, I'm going to open this in the text editor.
- 06:14We can see it's the exact same thing we've just been looking at on GitHub.
- 06:19And so we'll need to we'll need to obtain values for both of these for both of these keys.
- 06:26So, next public Superbase URL and then we'll also going to need a publishable key.
- 06:31Now, we have seen those already.
- 06:35So, remember in the previous video when we have run that first database command, it gave us this response with all of these with all of these like keys or
- 06:45like random characters and URLs and whatnot.
- 06:50So, this is exactly what we are going to use.
- 06:52The product URL is here and the publishable key is over here.
- 06:57So, all I need to do to do is just go over here, copy it and the publishable key is here.
- 07:06And in case you have closed the terminal from the previous lesson, no worries.
- 07:13If you actually go back to the GitHub and you go back to the README file, there is actually there is actually a helpful helpful command over here which reminds
- 07:24you what to do.
- 07:25It's the npm run database status.
- 07:29So, just run this command in this folder and you should have these like like similar or exact same kind of output.
- 07:40Make sure your Docker Desktop application is running though, okay?
- 07:44So, I'm going to I'm going to save my .env.local file.
- 07:50And with that, I'm going to start a new terminal.
- 07:54I'm going to again make sure this is I'm going to copy the path to this folder.
- 08:01So, command option C.
- 08:03I'm going to go current directory here and then I'm finally going to go with the npm run dev command, okay?
- 08:14So let's go npm run dev.
- 08:17And there we have it.
- 08:18Uh okay, let's see.
- 08:21The Next.js security version available.
- 08:23I'm going to skip it for now.
- 08:25Wasn't really expecting for this to come up here in the video.
- 08:28Um so I'm going to skip it for now.
- 08:30Uh and I'm just going to go and copy this URL.
- 08:34By the way, on my end, it's running on the port 3001 because the 3000 was already taken by the older um version of the um of the Tonik parking
- 08:46spot booking application from the previous module.
- 08:50But if I now go and like use this URL, there it is.
- 08:55We have our login screen and that is an application that we have cloned from GitHub and we have set it up all by ourselves locally.
- 09:03Again, we could have asked Claude to do all of this for us, but we did it manually.
- 09:09Next time, Claude is going to be doing these things for us.
- 09:11We know more or less what is happening in the background.
- 09:15So there is an email and there is a password.
- 09:18Um I don't know what credentials to use, but if I go back to the README file, I can actually see there is this test account section and I can
- 09:28find some basic credentials.
- 09:29I'm going to use Alex here and I 'm going to use password 1 2 3.
- 09:35Seems like it's the same password for everyone.
- 09:38And here I am and I am uh I'm in basically.
- 09:43That is the same app.
- 09:45The difference being this is now uh running like I can when I make um when I make a reservation, this is actually going to stick like on my local
- 09:54database. And so with that, um you know, we are officially done setting up application locally.
- 10:02And in the next video, we are finally going to go back to Claude so that it can help us to at first walk through of the codebase to explain
- 10:12what is what. So I'll see you in the next video.