Signing up and logging users in
In this section, we'll look at how to use Apollo Client and the Apollo library for Angular to add user authentication to our Angular frontend.
Defining GraphQL documents
Let's begin by defining the GraphQL documents (queries and mutations) required for user registration, signing in, and searching:
- Create a
shared/constants/auth.ts
file (make sure to create theconstants/
folder inside theshared/
folder) and begin by adding the following import and two string constants, containing the keys for the access token and authenticated user, which will be used to store the corresponding information in the user's browser's local storage:import { gql } from 'apollo-angular'; export const ACCESS_TOKEN: string = 'accessToken'; export const AUTH_USER: string = 'authUser';
- Add and export the register mutation that is sent to the backend API for registering users:
export const REGISTER_MUTATION =...