Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Test Authentication with API request #94

Merged
merged 3 commits into from
Apr 22, 2021
Merged

Conversation

mllemango
Copy link
Contributor

WHY are these changes introduced?

Fixes #90

WHAT is this pull request doing?

We need to ensure that oauth is fully functioning, so we can make a call to metafields to ensure oauth has succeeded. This was the approach that we used to implement Shopify/quilt#940

*Need to fix tests

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have added/updated tests for this change

@mllemango mllemango changed the title Check auth with API request Test Authentication with API request Apr 13, 2021
@avocadoslab
Copy link

Isn't there some lightweight ping pong like API which can confirm functionality? Occasionally I've seen huge latency with metafields fetch.

@mllemango
Copy link
Contributor Author

Since we're testing authentication, no I don't believe so.

Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

src/verify-request/tests/verify-request.test.ts Outdated Show resolved Hide resolved
@mllemango mllemango requested a review from a team April 16, 2021 13:50
@mllemango mllemango marked this pull request as ready for review April 16, 2021 17:38
Comment on lines +38 to +42
if (e instanceof HttpResponseError && e.code == 401){
// only catch 401 errors
} else {
throw e
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (e instanceof HttpResponseError && e.code == 401){
// only catch 401 errors
} else {
throw e
}
if (e instanceof HttpResponseError && e.code != 401) {
// only throw non-401 errors
throw e
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the lines just above this try block, there are identical lines in a PR by @carmelal
https://github.com/Shopify/shopify-node-api/blob/597c870978c9b6cb9b187ea240e1841f0bfd062a/src/auth/session/session.ts#L33-L34

I'm wondering if this change should wait for that other one to be merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only catches HttpResponseErrors, but I'm sure there could be more error types returned?

Oh, once carmela's PR is in, we could grab IsActive and use it here? Sounds good to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Carmela's changes are updating this same place, so we just need to make sure they're merged properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have a question about this block, which I think relates to Kevin's suggested change:
Since there is nothing in the if block, won't this not do anything with the error when it is a 401? Right now we only seem to throw in the else. Or is the intention for it to error silently in those cases (401)? Sorry if I'm missing something obvious here!

Copy link
Contributor Author

@mllemango mllemango Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! The intention is to error silently only on 401s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'silent error' here means we proceed as normal when there is no session - i.e. if the session expired we go to /auth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok! Then this works for me! Sorry I misunderstood the intention here.

Copy link
Contributor

@thecodepixi thecodepixi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Gracias for explaining the silent error situation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session is not updated when logging out and logging in again and the requests to backend stop working
6 participants