-
Notifications
You must be signed in to change notification settings - Fork 122
/
useCustomerType.ts
49 lines (43 loc) · 1.2 KB
/
useCustomerType.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import useAuthContext from './useAuthContext'
export type CustomerType = null | 'guest' | 'registered'
type useCustomerType = {
customerType: CustomerType
isGuest: boolean
isRegistered: boolean
}
/**
* A hook to return customer auth type.
*
* Customer type can have 3 values:
* - null
* - guest
* - registered
*
* During initialization, type is null. And it is possible that
* isGuest and isRegistered to both be false.
*
* @group Helpers
* @category Shopper Authentication
*
*/
const useCustomerType = (): useCustomerType => {
const auth = useAuthContext()
let customerType: string | null = auth.get('customer_type')
const isGuest = customerType === 'guest'
const isRegistered = customerType === 'registered'
if (customerType !== null && customerType !== 'guest' && customerType !== 'registered') {
customerType = null
}
return {
customerType,
isGuest,
isRegistered
}
}
export default useCustomerType