Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shopify-app-remix] get authenticated user details #472

Closed
boxedcode opened this issue Oct 21, 2023 · 7 comments
Closed

[shopify-app-remix] get authenticated user details #472

boxedcode opened this issue Oct 21, 2023 · 7 comments

Comments

@boxedcode
Copy link

Overview

Hi.

Currently, when authenticating a Shopify Remix app with authenticate.admin(request) with useOnlineTokens set to true, the session only contains the authenticated users id. I've had a look at the Admin API reference for graphql and rest and there doesn't appear to be a request to fetch the users details.

For some context, I have an app where I want to display a timeline of events for actions performed within the app, e.g.

Settings last updated by Joe on Oct 13, 2023 at 14:23

where Joe is a user who authenticated with my app.

How would I obtain Joe's name?

Thank you.

@joelvh
Copy link
Contributor

joelvh commented Oct 22, 2023

@boxedcode there should be an OAuth redirect to install the app (offline token) and then redirect again to authenticate the user (online token). The result should include both the offline and online token, with the user info under associated_user (something like this mocked response).

What session storage are you using?

@boxedcode
Copy link
Author

@joelvh Thanks for your response, appreciate it.

I'm using prisma for session storage with mysql as the storage engine. I'll go through the flow again to see if I can spot the user data in the session response

@boxedcode
Copy link
Author

I just went through the flow again, and the only data that appears to be populated for the session is the users id,

onlineAccessInfo: { associated_user: { id: 9854713913 } }

The default mysql schema for the shopify-app-remix template is

CREATE TABLE "Session" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "shop" TEXT NOT NULL,
    "state" TEXT NOT NULL,
    "isOnline" BOOLEAN NOT NULL DEFAULT false,
    "scope" TEXT,
    "expires" DATETIME,
    "accessToken" TEXT NOT NULL,
    "userId" BIGINT
);

and the documentation here reinforces the fact that only the id is available for the associated user. https://shopify.dev/docs/api/shopify-app-remix/v1/authenticate/admin#session-using-online-sessions

@byrichardpowell
Copy link
Contributor

byrichardpowell commented Oct 23, 2023

Hey 👋

Thanks for opening an issue, and sorry this functionality doesn't exist right now.

I'm going to close this issue as a duplicate of Shopify/shopify-app-template-remix#366

For context, we don't make this the default because we don't want an app to store sensitive PII information unless it has a reason to do so. Storing this information by default would increase the maintenance overhead of all apps, even though most apps don't need it.

But! I do appreciate there are very valid reasons why this information is useful, and you've written up a good use case here, thank you!

We should make this much more possible than it is right now, but we need to chat to a few people internally to see how.

@boxedcode
Copy link
Author

We should make this much more possible than it is right now, but we need to chat to a few people internally to see what is possible.

Thank you for your reply and confirming the current status of that functionality. I shall be patiently awaiting the conclusion of your internal discussions.

@nullndr
Copy link

nullndr commented Nov 13, 2023

Any news on this? I would like to retrieve the user locale to translate my app according. I can see from the types I should be able to get it via the session.toObject().onlineAccessInfo object but it is always undefined.

@ccarlosm
Copy link

ccarlosm commented Nov 21, 2023

Any news on this? I would like to retrieve the user locale to translate my app according. I can see from the types I should be able to get it via the session.toObject().onlineAccessInfo object but it is always undefined.

If using Remix template, check this:

https://community.shopify.com/c/technical-q-a/how-can-i-get-the-language-used-by-merchant-in-admin/m-p/1669398

In my case I used in the app.jsx loader:

const locale = new URL(request.url).searchParams.get('locale');

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

No branches or pull requests

5 participants