Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Basic components
VTEX Login app
Official extension
Version: 2.37.1
Latest version: 2.59.0

This page is about version 2.37.1 of the app, which is not the most recent version. The latest stable version is 2.59.0.

{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABCAIAAAB2XpiaAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAFUlEQVR4nGPg4+Mz1Nfjl5T7f2c+AAzxA3lptuDWAAAAAElFTkSuQmCC","img":{"src":"https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square","width":110,"height":20,"type":"svg"}}

Description

The VTEX Login app responsible to handle user login, and this app is used by store theme.

:loudspeaker: Disclaimer: Don't fork this project; use, contribute, or open issue with your feature request.

Release schedule

ReleaseStatusInitial ReleaseMaintenance LTS StartEnd-of-lifeStore Compatibility
[2.x]Current Release2018-11-082.x
[1.x]Maintenance LTS2018-07-262018-11-08March 20191.x

See our LTS policy for more information.

Table of Contents

Features

Query Parameters

This app reads the following Query String Parameters:

  • returnUrl - After the user logs in, he is redirected to the returnUrl. This parameter should be UTF-8 encoded (as of javascript's encodeURIComponent). The returnUrl only works for the store's domain.

  • oAuthRedirect - If this parameter is present, the user is directly redirected to the given OAuth Provider page before logging in, instead of displaying the login options. For this to work, the given OAuth Provider must be one of the login options. The parameter value is case sensitive and must be Google, Facebook or the registered name of the chosen OAuth Provider.

  • userEmail - The default value for user email fields.

  • flowState - The default state of the login flow to begin in. The possible values are from an enum with the following strings:

    • createPass - Create password state. When this is used, the query string userEmail must also be defined. On page view, an email will be sent to the user with the code required to create password.

Usage

This app uses our store builder with the blocks architecture. To know more about Store Builder click here.

We add the login as a block in our Store Header.

To configure or customize this app, you need to import it in your dependencies in manifest.json.


_10
"dependencies": {
_10
"vtex.login": "2.x"
_10
}

Then, add login or login-content block into your app theme as we do in our Store theme app. login-content is just the login form and login contains the login form and adds the possibility of other display modes such as pop-up.

Now, you can change the behavior of the login block that is in the store header. See an example of how to configure:


_10
"login": {
_10
"props": {
_10
"emailAndPasswordTitle": "LOG-IN",
_10
"accessCodeTitle": "Acess Code LOG-IN",
_10
"emailPraceholder": "e-mail",
_10
"passwordPlaceholder": "password",
_10
"showPasswordVerificationIntoTooltip": true,
_10
}
_10
}

This app also uses SVG icons from store-icons, which means any icons used by it can be customized. Use icon-profile, icon-eye-sight and icon-arrow-back blocks to configure these icons via props, if you wish to change their default size(height and width) or viewBox.

Blocks API

When implementing this app as a block, various inner blocks may be available. The following interface lists the available blocks within login and login-content and describes if they are required or optional.


_10
{
_10
"login": {
_10
"component": "Login"
_10
},
_10
"login-content": {
_10
"component": "LoginContent"
_10
}
_10
}

For now these blocks do not have any required or optional blocks.

Configuration

Through the Storefront, you can change the login's behavior and interface. However, you also can make in your theme app, as Store theme does.

Prop nameTypeDescriptionDefault value
optionsTitleStringSet title of login options-
emailAndPasswordTitleStringSet title of login with email and password-
accessCodeTitleStringSet title of login by access code-
emailPlaceholderStringSet placeholder to email input-
passwordPlaceholderStringSet placeholder to password input-
showPasswordVerificationIntoTooltipBooleanSet show password format verification as tooltip-
acessCodePlaceholderStringSet placeholder to access code input-
showIconProfileBooleanEnables icon hpa-profile-
iconSize (DEPRECATED - use icon blocks instead)NumberSet size of the profile icon-
iconLabelStringSet label of the login button-
hideIconLabelbooleanWhether the Login button label should be hidden (true) or not (false).false
labelClassesStringLabel's classnames-
providerPasswordButtonLabelStringSet Password login button text-
hasIdentifierExtensionBooleanEnables identifier extension configurations-
identifierPlaceholderStringSet placeholder for the identifier extension-
invalidIdentifierErrorStringSet error message for invalid user identifier-
mirrorTooltipToRightBooleanMakes login tooltip open towards the right sidefalse
logInButtonBehaviorEnumSet log in button behavior. "popover" for popover, "link" for a link to the /login page"popover"
accountOptionsButtonBehaviorEnumSet account options button behavior. "popover" for popover, "link" for a link to the /account page"popover"
accountOptionLinksArrayDetermines more specific account option links to replace the My Account link.
Each array element is an object with the properties:
  • label [string] - Link text
  • path [string] - Relative path to where the link leads
  • cssClass [string] - CSS class the link receives
-
termsAndConditionsStringSets a markdown text below the login options, meant to warn the user about terms & conditions-
hasGoogleOneTapboolean
{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAI0lEQVR4nGO4Ge70f82ED0Uxi2QFGdwYGOabqq1zNAhiYAAAkfgI7Rdimv8AAAAASUVORK5CYII=","img":{"src":"https://img.shields.io/badge/-Beta-red","width":35,"height":20,"type":"svg"}}
Defines whether the Google's One-tap sign-up and auto sign-in solution is enabled (true) or not (false) .
false
googleOneTapAlignmentenum
{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAI0lEQVR4nGO4Ge70f82ED0Uxi2QFGdwYGOabqq1zNAhiYAAAkfgI7Rdimv8AAAAASUVORK5CYII=","img":{"src":"https://img.shields.io/badge/-Beta-red","width":35,"height":20,"type":"svg"}}
Defines pop-up alignment for the Google One-tap login. Possible values are Left and Right.
Right
googleOneTapMarginTopstring
{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAI0lEQVR4nGO4Ge70f82ED0Uxi2QFGdwYGOabqq1zNAhiYAAAkfgI7Rdimv8AAAAASUVORK5CYII=","img":{"src":"https://img.shields.io/badge/-Beta-red","width":35,"height":20,"type":"svg"}}
Defines the pop-up top margin for the Google One-tap login. The values supported are the same supported by the CSS property top.
3rem

Note that the Google One Tap props are in Beta. Although they are ready to be used, you can expect some UX and customization improvements.

You can also change the login-content's behaviour and interface through the Store front.

Prop nameTypeDescriptionDefault value
isInitialScreenOptionOnlyBooleanSet to show only the login options on the initial screentrue
defaultOptionEnumSet the initial form to show. 0 for access code login, 1 for email and password login0
optionsTitleStringSet title of login options-
emailAndPasswordTitleStringSet title of login with email and password-
accessCodeTitleStringSet title of login by access code-
emailPlaceholderStringSet placeholder to email input-
passwordPlaceholderStringSet placeholder to password input-
showPasswordVerificationIntoTooltipBooleanSet show password format verification as tooltip-
acessCodePlaceholderStringSet placeholder to access code input-
providerPasswordButtonLabelStringSet Password login button text-
hasIdentifierExtensionBooleanEnables identifier extension configurations-
identifierPlaceholderStringSet placeholder for the identifier extension-
invalidIdentifierErrorStringSet error message for invalid user identifier-
termsAndConditionsStringSets a markdown text below the login options, meant to warn the user about terms & conditions-

Plugins API

This app can be extended through the plugins.json file of the store builder. The extension is only allowed for enterprise clients and can change the login functionality. It is explained in the following section.

User Identifier Extension

The Email/Password login takes two inputs:

  • The user email (his identifier)
  • The user password

The User Identifier Extension allows other identifiers to be used in the login form, as long as it can be resolved to the user email. For example, if your account stores the National Identity Document of each user, the Email/Password login would be changed to ask for the following two inputs:

  • The user National Identity Document (his identifier)
  • The user password

There is a limitation to this feature. Every user must have an email to be logged in, so the user identifier must be able to be resolved to an email. If you want to use an identifier other than the email, you must create a resolver app (or an extension app) that returns an email, given an identifier. For example, imagine the user John, whose email is john@example.com and whose National Identity Document is 12345. When he types his document (12345), your app must receive the 12345, find out that it belongs to John, find out that John's email is john@example.com and return this email to the login app.

When an extension app returns an email to the login app, it acts like the user just typed in that email. So if it returns null, for example, a message like "The email is invalid" will appear. This message, along with some others, may be edited in the Store Front, as described in the Blocks API section (eg. "The User Identifier Extension is invalid").

Creating the User Identifier Extension App

To create your extension app, there are five steps you must worry about.

  • First, you must add login as your app's dependency. In the manifest.json file:

_10
"dependencies": {
_10
"vtex.login": "2.x"
_10
},

  • Second, you need to add the store builder to your app. In the manifest.json file:

_10
"builders": {
_10
"store": "0.x",
_10
},

  • Third, you must extend the user-identifier interface defined by the login app. You can choose any interface name you want, which will be represented here by {{InterfaceName}}. You will need to create a component for that interface, but for now it will be represented by {{ComponentName}}. In the store/interfaces.json file:

_10
"user-identifier.{{InterfaceName}}": {
_10
"component": "{{ComponentName}}"
_10
},

  • Fourth, you must plug in your interface to the login app. In the store/plugins.json file:

_10
"login > user-identifier": "user-identifier.{{InterfaceName}}",
_10
"login-content > user-identifier": "user-identifier.{{InterfaceName}}",

  • Fifth, you need to create the component that you decided to name {{ComponentName}}. This component will replace the email input in the login form. This means that it could render anything, like a File Uploader or a simple Text Input which takes a National Identity Document. Just remember that this component must know how to convert the data it receives to an email. This is done by registering a callback function that returns an email whithin the login app. It will be defined in the file react/{{ComponentName}}.js. The following example is a good template to be used, and is commented so you understand each of its parts:

_39
import { useState, useCallback, useEffect } from 'react'
_39
_39
const ComponentName = ({ renderInput, identifierPlaceholder, registerSubmitter }) => {
_39
// The component receives 3 props:
_39
// - renderInput is a function that returns the same Input component used by the login app, defined in styleguide.
_39
// It receives an object with three named parameters, trivially used by Inputs with react: value, onChange, placeholder.
_39
// When "onChange" is called, the login app clears the "email is invalid" error, if it exists.
_39
// - identifierPlaceholder is the value of the configuration "identifierPlaceholder" defined in the Store Front. It has a
_39
// fallback to the value of the configuration "emailPlaceholder".
_39
// - registerSubmitter is a function that receives your async callback function defined in this file. Your callback will be called
_39
// when the user submits the form.
_39
_39
// This code controls the state of the rendered Input component.
_39
const [inputValue, setInputValue] = useState('')
_39
const onChangeInput = useCallback(e => setInputValue(e.target.value), [
_39
setInputValue,
_39
])
_39
_39
// This callback function (onSubmit) should return the resolved email. In the example below, it adds `@email.com` to the current
_39
// value in the Input component (eg. "john" would be resolved to "john@email.com").
_39
const onSubmit = useCallback(async () => {
_39
const email = `$\{inputValue\}@email.com`
_39
return email
_39
}, [inputValue])
_39
_39
// This code registers the async callback function you defined in the login app when this component mounts.
_39
useEffect(() => {
_39
registerSubmitter(onSubmit)
_39
}, [registerSubmitter, onSubmit])
_39
_39
// The component calls "renderInput" and renders its result.
_39
return renderInput({
_39
value: inputValue,
_39
onChange: onChangeInput,
_39
placeholder: identifierPlaceholder,
_39
})
_39
}
_39
_39
export default ComponentName

After following the five steps, your extension app will be good to go. Just install it in your account and it will replace the email Input in the login form.

Styles API

This app provides some CSS classes as an API for style customization.

To use this CSS API, you must add the styles builder and create an app styling CSS file.

  1. Add the styles builder to your manifest.json:

_10
"builders": {
_10
"styles": "1.x"
_10
}

  1. Create a file called vtex.login.css inside the styles/css folder. Add your custom styles:

_10
.container {
_10
margin-top: 10px;
_10
}

CSS namespaces

Class nameDescriptionComponent Source
containerLogin main containerLoginComponent
contentInitialScreenLogin Content initial screenLoginContent
contentFormVisibleLogin Content formLoginContent
profileProfile email or name when logged inLoginComponent
labelIcon labelLoginComponent
optionsStickyLogin options in sticky modeLoginOptions
optionsListLogin options listLoginOptions
optionsListItemLogin options itemLoginOptions
optionsListItemContainerContainer in Login optionsLoginOptions
accessCodeOptionBtnAccess Code login option buttonLoginOptions
emailPasswordOptionBtnEmail/ Password login option buttonLoginOptions
facebookOptionBtnFacebook login option buttonOAuth
googleOptionBtnGoogle login option buttonOAuth
customOAuthOptionBtnCustom OAuth login option buttonOAuth
oauthProviderOAuth provider nameOAuth
inputContainerAny input containerCodeConfirmation, EmailAndPassword, EmailVerification, RecoveryPassword
inputContainerAccessCodeAccess code input containerCodeConfirmation, RecoveryPassword
inputContainerPasswordPassword input containerEmailAndPassword, RecoveryPassword
inputContainerEmailEmail input containerEmailAndPassword, EmailVerification
emailVerificationEmail verification formEmailAndPassword, EmailVerification, RecoveryPassword
emailFormEmail form to send access codeEmailVerification
emailAndPasswordFormForm containing email and passwordEmailAndPassword
forgotPasswordForm"Forgot Password" formRecoveryPassword
formLinkContainerContainer for linksEmailAndPassword
arrowUpArrow upLoginComponent
buttonLinkButton linkLoginComponent
formErrorError formLoginComponent
contentLogin Content containerLoginContent
content--emailVerificationContainer during emailVerification flowLoginContent
content--emailAndPasswordContainer during emailAndPassword flowLoginContent
content--codeConfirmationContainer during codeConfirmation flowLoginContent
content--accountOptionsContainer during accountOptions flowLoginContent
content--recoveryPasswordContainer during recoveryPassword flowLoginContent
buttonAny buttonAccountOptions, LoginOptions, OAuth
sendButtonButtons sending informationsCodeConfirmation, EmailAndPassword, EmailVerification, RecoveryPassword
buttonSocialButton to social mediaOAuth
buttonDangerDanger buttonLoginOptions
backButtonBack buttonGoBackButton
accountOptionsAccount options containerAccountOption
codeConfirmationCode Confirmation containerCodeConfirmation
formTitleForm TitleFormTitle
formSubtitleForm SubtitleFormTitle
boxLogin boxLoginContent
contentContainerLogin content containerLoginContent
formFooterForm footer containerFormFooter
contentFormLogin Content formLoginContent
contentAlwaysWithOptionsLogin content with optionsLoginContent
optionsLogin Options containerLoginOptions
tooltipContainerTooltip ContainerTooltip
tooltipContainerTopTooltip TopTooltip
tooltipContainerLeftTooltip LeftTooltip
termsAndConditionsContainer below login optionsLoginContent
forgotPasswordLinkLink to create new password flowEmailAndPassword
dontHaveAccountLink to create account flowEmailAndPassword
eyeIconButton that makes password visiblePasswordInput

Troubleshooting

You can check if others are passing through similar issues here. Also feel free to open issues or contribute with pull requests.

Contributing

Check it out how to contribute with this project.

Tests

To execute our tests go to react/ folder and run yarn test

Travis CI

{"base64":"  ","img":{"width":98,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":730,"url":"https://api.travis-ci.com/vtex-apps/login.svg?branch=master"}}

See also
VTEX App Store
VTEX IO Apps