-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 get customer login flow and account/orders landing page working
- Loading branch information
Showing
12 changed files
with
189 additions
and
769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
templates/skeleton/app/graphql/customer/CustomerDetailsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// https://shopify.dev/docs/api/customer/latest/queries/customer | ||
export const CUSTOMER_DETAILS_QUERY = `#graphql:customer | ||
query Customer { | ||
customer { | ||
firstName | ||
lastName | ||
} | ||
} | ||
` as const; |
51 changes: 51 additions & 0 deletions
51
templates/skeleton/app/graphql/customer/CustomerOrdersQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const ORDER_ITEM_FRAGMENT = `#graphql:customer | ||
fragment OrderItem on Order { | ||
totalPrice { | ||
amount | ||
currencyCode | ||
} | ||
financialStatus | ||
id | ||
number | ||
processedAt | ||
} | ||
` as const; | ||
|
||
export const CUSTOMER_FRAGMENT = `#graphql:customer | ||
fragment CustomerOrders on Customer { | ||
orders( | ||
sortKey: PROCESSED_AT, | ||
reverse: true, | ||
first: $first, | ||
last: $last, | ||
before: $startCursor, | ||
after: $endCursor | ||
) { | ||
nodes { | ||
...OrderItem | ||
} | ||
pageInfo { | ||
hasPreviousPage | ||
hasNextPage | ||
endCursor | ||
startCursor | ||
} | ||
} | ||
} | ||
${ORDER_ITEM_FRAGMENT} | ||
` as const; | ||
|
||
// https://shopify.dev/docs/api/customer/latest/queries/customer | ||
export const CUSTOMER_ORDERS_QUERY = `#graphql:customer | ||
${CUSTOMER_FRAGMENT} | ||
query CustomerOrders( | ||
$endCursor: String | ||
$first: Int | ||
$last: Int | ||
$startCursor: String | ||
) { | ||
customer { | ||
...CustomerOrders | ||
} | ||
} | ||
` as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import {redirect, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; | ||
|
||
// fallback wild card for all unauthenticated rouutes in account sectiion | ||
export async function loader({context}: LoaderFunctionArgs) { | ||
if (await context.session.get('customerAccessToken')) { | ||
return redirect('/account'); | ||
console.log('\x1b[45m%s\x1b[0m', `-------Account Fallback---------`); | ||
|
||
if (!(await context.customerClient.isLoggedIn())) { | ||
console.log( | ||
'\x1b[36m%s\x1b[0m', | ||
`-------Account Fallback login check fail---------`, | ||
); | ||
return redirect('/account/login'); | ||
} | ||
return redirect('/account/login'); | ||
|
||
return redirect('/account'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {redirect} from '@shopify/remix-oxygen'; | ||
|
||
export async function loader() { | ||
return redirect('/account/orders'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.