Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- getAuthenticatedUser endpoint

## [2.173.2] - 2025-07-31

## [2.173.2] - 2025-07-28
Expand Down
5 changes: 5 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ type Query {
salesChannel: String
postalCode: String
): [SKU] @cacheControl(scope: SEGMENT, maxAge: SHORT) @withSegment

"""
Returns information about the currently authenticated user
"""
authenticatedUser: AuthenticatedUserInfo @cacheControl(scope: PRIVATE)
}

type Mutation {
Expand Down
26 changes: 26 additions & 0 deletions graphql/types/Session.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,29 @@ type SessionPickup {
name: String
address: Address
}

"""
Detailed information about the authenticated user from VTEX ID
"""
type AuthenticatedUserInfo {
"""
User unique identifier
"""
id: String
"""
User email address
"""
email: String
"""
User display name
"""
name: String
"""
Date when password was last updated
"""
passwordLastUpdate: String
"""
Organization unit the user belongs to
"""
organizationUnit: String
}
5 changes: 5 additions & 0 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IOClients } from '@vtex/api'
import { CallCenterOperator } from './callCenterOperator'
import { Catalog } from './catalog'
import { Checkout } from './checkout'
import { VtexId } from './vtexid'
import { PvtCheckout } from './PvtCheckout'
import { MasterData } from './masterdata'
import { ProfileClient } from './profile'
Expand Down Expand Up @@ -71,4 +72,8 @@ export class Clients extends IOClients {
public get rewriter() {
return this.getOrSet('rewriter', Rewriter)
}

public get vtexId() {
return this.getOrSet('vtexId', VtexId)
}
}
27 changes: 27 additions & 0 deletions node/clients/vtexid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { JanusClient } from '@vtex/api'

export interface AuthenticatedUserResponse {
user: string
userId: string
locale: string
}

export class VtexId extends JanusClient {
public getAuthenticatedUser = () => {
const { storeUserAuthToken = '', account } = this.context

if (!storeUserAuthToken) {
throw new Error('User is not authenticated')
}

return this.http.get<AuthenticatedUserResponse>(`/api/vtexid/user/info`, {
metric: 'vtexid-authenticated-user',
headers: {
Cookie: `VtexIdclientAutCookie_${account}=${storeUserAuthToken}`,
},
params: {
scope: account,
},
})
}
}
1 change: 1 addition & 0 deletions node/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare global {
}

interface CustomIOContext extends IOContext {
getAuthenticatedUser(): unknown
currentProfile: CurrentProfile
segment?: SegmentData
orderFormId?: string
Expand Down
7 changes: 7 additions & 0 deletions node/resolvers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ const checkPasswordFormat = (password: any) => {
}

export const queries = {
/**
* Get information about the currently authenticated user
*/
authenticatedUser: async (_: any, __: any, ctx: any) => {
return ctx.clients.vtexId.getAuthenticatedUser()
},

/**
* Request to the VTEX ID API the list of available login
* options to the user authentication.
Expand Down
Loading