-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
giraud florent
committed
Aug 6, 2023
1 parent
998ee2f
commit e68ff2a
Showing
5 changed files
with
32 additions
and
20 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
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
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
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,13 +1,25 @@ | ||
import { useNuxtApp } from "#imports" | ||
|
||
import { onBeforeMount, useNuxtApp, useState } from "#imports" | ||
import { Stripe } from '@stripe/stripe-js' | ||
/** | ||
* useClientStripe function | ||
* | ||
* This function is a helper to easily access the Stripe instance provided by the Nuxt plugin. | ||
* It can be used in components or pages to interact with the Stripe.js library. | ||
* | ||
*/ | ||
export default function useClientStripe() { | ||
if (process.server) return null | ||
return useNuxtApp().$stripe() | ||
export default async function useClientStripe() { | ||
const nuxtApp = useNuxtApp() | ||
const stripe = useState<Stripe>('stripe-client', () => null) | ||
const isLoading = useState('stripe-client-loading', () => false) | ||
|
||
onBeforeMount(async () => { | ||
if (!isLoading.value) { | ||
isLoading.value = true | ||
const _stripe = await nuxtApp.$stripe._loadStripe() | ||
stripe.value = _stripe | ||
isLoading.value = false | ||
} | ||
}) | ||
|
||
return stripe | ||
} |
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