question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Universal auth error every time

See original GitHub issue

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v14.16.0

Amplify CLI Version

4.44.0

What operating system are you using?

Mac

Amplify Categories

auth, api

Amplify Commands

Not applicable

Describe the bug

We have created an angular amplify project which works fine in all cases apart from when hosting the angular project as an SSR Universal application. In this case, the project still works to the users, however it consistently gives this error for the first few calls:

GraphQLAPI - ensure credentials error No Cognito Identity pool provided for unauthenticated access

The app still serves the content correctly, however because of this the universal server side rendering doesnt work as well as it should and therefore google’s crawler doesnt pick up the pages correctly.

// Main.ts
import awsconfig from "./aws-exports";
Auth.configure(awsconfig);
API.configure(awsconfig);

and I have all the cognito and amplify settings set up correctly to allow user pools and unauthenticated users using IAM - as they all work fine for our web app and Ionic app.

I can’t understand why then, the angular universal project gets this error.

Expected behavior

It should not give an auth error.

Reproduction steps

  1. Create angular universal project
  2. Make any unauthenticated call for some data from the api:
  public runQuery<T>(query: any, variables: any, mapField: string, iamMode?: boolean, hideToast?: boolean): Observable<T | ErrorType> {
    return from(API.graphql({
      query,
      variables,
      authMode: !iamMode ? GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS : GRAPHQL_AUTH_MODE.AWS_IAM
    }))
      .pipe(
        map((res: GraphQLResult<T>) => res?.data[mapField]),
        catchError(err => {
          console.log('API Service calling the query: ' + mapField);
          console.error(err);
          return of(ErrorType.ERROR);
        }),
        first(),
      )
  }

Log output

# Put your logs below this line
Node Express server listening on http://localhost:4000
[WARN] 19:45.186 GraphQLAPI - ensure credentials error No Cognito Identity pool provided for unauthenticated access
Error: No credentials
    at GraphQLAPIClass.<anonymous> (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:12792569)
    at step (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:12789146)
    at Object.next (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:12789262)
    at fulfilled (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:12787741)
    at ZoneDelegate.invoke (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:11013148)
    at Object.onInvoke (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:2500846)
    at ZoneDelegate.invoke (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:11013044)
    at Zone.run (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:11005562)
    at /Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:11024659
    at ZoneDelegate.invokeTask (/Users/ollie/Documents/Development/Ping-web-version/dist/server/main.js:1:11014080)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sky4gitcommented, May 20, 2021

I suggest remove “@aws-amplify” sub packages from package.json as dependencies. For example, “@aws-amplify/ui-react”: “^0.2.34”

0reactions
Milan-Shahcommented, Nov 23, 2021

@oliverandersencox - We have released a major new version of @aws-amplify/ui-react@2.1.0. Please give it a try and let us know if you are still facing any auth issues. We are here to help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Universal auth error every time · Issue #280 - GitHub
and I have all the cognito and amplify settings set up correctly to allow user pools and unauthenticated users using IAM - as...
Read more >
Angular Universal - Auth Guard pending problem
Behavior without Angular Universal is when page is reloaded It just open up popup for login.
Read more >
Server-side rendering (SSR) with Angular Universal
This guide describes Angular Universal, a technology that renders Angular applications on the server. A normal Angular application executes in the browser, ...
Read more >
Angular Universal: real app problems - InDepth.Dev
The project makes server-side rendering possible in Angular. This article will discuss the issues and possible solutions we encountered while developing a real ......
Read more >
The Complete Guide to Angular User Authentication with Auth0
The focus of this guide is to help developers learn how to secure an Angular application by implementing user authentication.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found