getMe
Method fetching current user data (i.e cart and customer profile).
This method sends a POST request to the getMe endpoint of the Vue Storefront API Middleware. In turn, it fetches a customer from commercetools by sending a request to its GraphQL API.
If the customer parameter is not passed, this method uses the getMeBasicProfileDefaultQuery GraphQL query. Else, it uses the getMeFullProfileDefaultQuery query.
When vsf-commercetools-token cookie is present in the browser, this method will fetch data of the user (anonymous or authenticated) linked to the token. In case there is no cookie, it will return an empty data object.
Signature
export declare function getMe<Res extends PartialGetMeResponse = GetMeResponse>(
params?: GetMeParams,
options?: MethodOptions<CustomQuery<"getBasicProfile" | "getFullProfile">>
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
params | Optional | GetMeParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions<CustomQuery<"getBasicProfile" | "getFullProfile">> | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of the GetMeResponse.
Referenced Types
Examples
Fetching basic user profile (i.e. cart).
import { sdk } from '~/sdk.config.ts';
const { me } = await sdk.commerce.getMe();Fetching full user profile (i.e. cart and customer profile).
import { sdk } from '~/sdk.config.ts';
const { me } = await sdk.commerce.getMe({ customer: true });Creating a custom GraphQL query for fetching basic user profile in middleware.config.js.
module.exports = {
integrations: {
ct: {
// ...
customQueries: {
'get-me-basic-custom-query': ({ query, variables, metadata }) => ({
variables,
query: `
query getBasicProfile {
me {
activeCart {
${metadata}
}
}
}
`
}),
}
}
}
};Fetching basic user profile and using the customQuery parameter to leverage the custom GraphQL query from the previous example. Notice how we are using the type parameter to overwrite the default response interface.
import { sdk } from '~/sdk.config.ts';
type CustomGetMeResponse = {
me: {
activeCart: {
id: string;
version: string;
}
}
}
const { me } = await sdk.commerce.getMe<CustomGetMeResponse>(undefined, {
customQuery: {
getBasicProfile: 'get-me-basic-custom-query',
metadata: 'id,version'
}
});Creating a custom GraphQL query for fetching full user profile in middleware.config.js.
module.exports = {
integrations: {
ct: {
// ...
customQueries: {
'get-me-full-custom-query': ({ query, variables, metadata }) => ({
variables,
query: `
query getFullProfile {
me {
activeCart {
${metadata.activeCart}
}
customer {
${metadata.customer}
}
}
}
`
}),
}
}
}
};Fetching full user profile and using the customQuery parameter to leverage the custom GraphQL query from the previous example. Notice how we are using the type parameter to overwrite the default response interface.
import { sdk } from '~/sdk.config.ts';
type CustomGetMeResponse = {
me: {
activeCart: {
id: string;
},
customer: {
id: string;
}
}
}
const { me } = await sdk.commerce.getMe({ customer: true }, {
customQuery: {
getFullProfile: 'get-me-full-custom-query',
metadata: { activeCart: 'id', customer: 'id' }
}
});