Skip to main content

Account Section

After your customers create their accounts and log in using their credentials, they will land at their account dashboard. The Account Section will be used within the /account page to give your authenticated customers access to their orders, address, and more. Before we create the /account page, let's create the Account Section.

  1. On your local environment, create a new folder inside src/sections and name it as Account.

  2. Create an index.js file inside the Account folder.

  3. Create a styles.module.css file inside the Account folder.

Shopify

import * as React from 'react'
import { useCustomerActions, useCustomerState } from 'frontend-customer'
import Link from 'frontend-link'
import AuthGuard from 'Components/AuthGuard'

const Account = () => {
const { getAllAddresses, logout, updateDefaultAddress } = useCustomerActions()
const customerState = useCustomerState()

const { addresses, defaultAddress, email, displayName, firstName, isLoggedIn, lastName, status } =
customerState

React.useEffect(() => {
if (isLoggedIn) getAllAddresses()
}, [isLoggedIn, getAllAddresses])

return (
<section>
<h1>Your account</h1>
{isLoggedIn && (
<button onClick={logout}>Sign Out</button>
)}

<AuthGuard allowedAuthStatus="authenticated" redirectUrl="/account/login">
<Link href="/account/orders">Orders</Link>

<div>
<div>
<strong>Name:</strong>
<p>{displayName || [firstName, lastName].join(' ')}</p>
</div>

<div>
<strong>Email:</strong>
<p>{email}</p>
</div>

<div>
<strong>Password:</strong>
<p aria-hidden="true">********</p>

<Link href="/account/reset-password">
Change password
</Link>
</div>

{addresses && (
<div>
<strong>Addresses:</strong>
{addresses.length > 0
? addresses.map(
({ address1, address2, city, country, id, phone, province, zip }) => (
<div>
<address>
<p>{address1}</p>
{address2 && <p>{address2}</p>}
<p>{city}, {province}, {zip}</p>
<p>{country}</p>
{phone && <a href={'tel:'+ phone}>{phone}</a>}
</address>
<div>
<Link href={'/account/address?id=' + id}>Edit address</Link>
{defaultAddress && defaultAddress.id === id ? (
<strong>Default</strong>
) : (
<button onClick={() => updateDefaultAddress(id)}>
Make default
</button>
)}
</div>
</div>
)
)
: ' n/a'}
<Link href={addressUrl}>Add new address</Link>
</div>
)}
</div>
</AuthGuard>
</section>
)
}

export default Account

BigCommerce

import * as React from 'react'
import { useCustomerActions, useCustomerState } from 'frontend-customer'
import Link from 'frontend-link'
import AuthGuard from 'Components/AuthGuard'

const Account = () => {
const { getAllAddresses, logout } = useCustomerActions()
const customerState = useCustomerState()

const { addresses, email, firstName, isLoggedIn, lastName, status } = customerState

React.useEffect(() => {
if (isLoggedIn) getAllAddresses()
}, [isLoggedIn, getAllAddresses])

return (
<section>
<h1>Your account</h1>
{isLoggedIn && (
<button onClick={logout}>Sign Out</button>
)}

<AuthGuard allowedAuthStatus="authenticated" redirectUrl="/account/login">
<Link href="/account/orders">Orders</Link>

<div>
<div>
<strong>Name:</strong>
<p>{[firstName, lastName].join(' ')}</p>
</div>

<div>
<strong>Email:</strong>
<p>{email}</p>
</div>

<div>
<strong>Password:</strong>
<p aria-hidden="true">********</p>

<Link href="/account/reset-password">Change password</Link>
</div>

{addresses && (
<div>
<strong>Addresses:</strong>
{addresses.length > 0
? addresses.map(
({ address1, address2, city, country, id, phone, province, zip }) => (
<div>
<address>
<p>{address1}</p>
{address2 && <p>{address2}</p>}
<p>{city}, {province}, {zip}</p>
<p>{country}</p>
{phone && <a href={'tel:' + phone}>{phone}</a>}
</address>
<Link href={'/account/address?id=' + id}>
Edit address
</Link>
</div>
),
)
: ' n/a'}
<Link href="/account/address">Add new address</Link>
</div>
)}
</div>
</AuthGuard>
</section>
)
}

export default Account

Account page

With the Account Section ready, let's create the /account page:

  1. Click on the Pages icon from the sidebar.

  2. Click ADD PAGE on the top right corner.

  3. Enter the PAGE NAME: Account.

  4. Enter the PAGE PATH: account.

  5. If you want, you can select a Frame from the Frame dropdown.

  6. Click ADD PAGE.

Now, add the Account section to your Account page (if you are already on the Account page, skip to step 4):

  1. Click on the Pages icon from the sidebar.

  2. Search for "Account".

  3. Open the "Account" page by clicking on its title.

  4. On the sidebar, click on the + (plus sign) where it says "Add sections to start building your page".

  5. A list with all our Sections will appear, search for and select Account.

  6. Click SAVE.

1582
Did this answer your question?