Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

4 - Authenticating users

This folder contains the sample code for the Authenticating users tutorial. Please refer to the tutorial for instructions on configuring, running, and deploying this sample.

Simple instructions

  1. Install Node.js.

    • Optional: Install Yarn.
  2. Install git.

  3. Create a Google Cloud Platform project.

  4. Install the Google Cloud SDK.

    • After downloading the SDK, initialize it:

        gcloud init
      
  5. Acquire local credentials for authenticating with Google Cloud Platform services:

    gcloud beta auth application-default login
    
  6. Clone the repository:

    git clone https://github.com/GoogleCloudPlatform/nodejs-getting-started.git
    
  7. Change directory:

    cd nodejs-getting-started/4-auth
    
  8. Create a config.json file (copied from the config-default.json file):

    cp config-default.json config.json
    
    • Set GCLOUD_PROJECT in config.json to your Google Cloud Platform project ID.
    • Set DATA_BACKEND in config.json to one of "datastore", "cloudsql", or "mongodb".
    • Set CLOUD_BUCKET in config.json to the name of your Google Cloud Storage bucket.
    • Set OAUTH2_CLIENT_ID in config.json.
    • Set OAUTH2_CLIENT_SECRET in config.json.
  9. Install dependencies using NPM or Yarn:

    • Using NPM:

        npm install
      
    • Using Yarn:

        yarn install
      
  10. Configure the backing store:

    • If DATA_BACKEND is set to "cloudsql":

      1. Create a Cloud SQL instance, and download and start the Cloud SQL proxy:

        Instructions for doing so: https://cloud.google.com/nodejs/getting-started/using-cloud-sql#creating_a_cloud_sql_instance

      2. Set MYSQL_USER in config.json, e.g. "my-cloudsql-username".

      3. Set MYSQL_PASSWORD in config.json, e.g. "my-cloudsql-password".

      4. Set INSTANCE_CONNECTION_NAME in config.json, e.g. "YOUR_PROJECT_ID:YOUR_REGION:YOUR_INSTANCE_ID".

      5. Run the script to setup the table:

        • Using NPM:

            npm run init-cloudsql
          
        • Using Yarn:

            yarn run init-cloudsql
          
    • If DATA_BACKEND is set to "mongodb":

      1. Set MONGO_URL in config.json, e.g. "mongodb://username:password@123.45.67.890:27017".
  11. Start the app using NPM or Yarn:

    • Using NPM:

        npm start
      
    • Using Yarn:

        yarn start
      
  12. View the app at http://localhost:8080.

  13. Stop the app by pressing Ctrl+C.

  14. Deploy the app:

    gcloud app deploy
    
  15. View the deployed app at https://YOUR_PROJECT_ID.appspot.com.