User Creation

Let's create the service, auth, that will handle user creation and authentication and learn to send the user creation request to the API.

Create auth service

The first thing we’ll do is create the service we’ll use to handle user creation and authentication.

ng g service services/auth/auth
  • This command creates a /services directory with another directory, /auth, that contains our service and its associated test file.
  • We create this /services directory to hold all our services so they don’t pollute our src/app directory.

If you’re curious about what the CLI will generate for you, there’s a handy flag -d, which stands for dry run that you can add to your CLI commands to run the command without making any changes to your code.

ng g service services/auth/auth -d

This will list the files that would have been created or updated had the same command been run without the flag. It’s useful in cases like this where we’re creating new directories with the CLI and we want to double-check that everything is right before we create the files. We’ll take another look at this in the next section.

Get hands-on with 1400+ tech skills courses.