Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Adds deleteCurrentSession function #60

Merged
merged 2 commits into from
Dec 18, 2020
Merged

Conversation

thecodepixi
Copy link
Contributor

WHY are these changes introduced?

We have deleteSession but this requires first grabbing the session you want to delete to pass to that function. This essentially wraps that and does both: regardless of session type (JWT or Cookie) it will find the current session based on the current request and delete it from session storage for you.

WHAT is this pull request doing?

Adds the deleteCurrentSession method and testing. This method follows a similar pattern to loadCurrentSession.

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)

@thecodepixi thecodepixi requested a review from a team as a code owner December 18, 2020 18:03
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.

Minor tweaks but looking solid! If possible, I'd like to get a third opinion on whether exceptions are the way to go (I think they are).

src/utils/delete-current-session.ts Outdated Show resolved Hide resolved
const jwtPayload = decodeSessionToken(matches[1]);
const jwtSessionId = ShopifyOAuth.getJwtSessionId(jwtPayload.dest.replace(/^https:\/\//, ''), jwtPayload.sub);
await Context.deleteSession(jwtSessionId);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're always throwing when errors occur, do we still need to return true on success?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have an opinion on a good alternative? Our base deleteSession also returns true for successful deletion right now.

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 that makes sense for the session storage since we need to know if the operation succeeded. But here, success means not hitting an error, so it doesn't have to return anything IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was wrong, deleteSession returns true regardless, but I'm not sure how I feel about that.

src/utils/test/delete-current-session.test.ts Outdated Show resolved Hide resolved
src/utils/test/delete-current-session.test.ts Outdated Show resolved Hide resolved
@paulomarg
Copy link
Contributor

Minor tweaks but looking solid! If possible, I'd like to get a third opinion on whether exceptions are the way to go (I think they are).

@andyw8 can I trouble you for some thoughts around this?

@thecodepixi thecodepixi merged commit fc6bbcd into main Dec 18, 2020
@thecodepixi thecodepixi deleted the add-delete-current-session branch December 18, 2020 20:47
@paulomarg paulomarg temporarily deployed to production January 13, 2021 19:45 Inactive
@paulomarg paulomarg temporarily deployed to production January 27, 2021 19:19 Inactive
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants