sveltekit-pocketbase-starter
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "sveltekit-pocketbase-starter", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "Dominick Caponi <d.caponi1@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,5 +26,3 @@ import { redirect } from '@sveltejs/kit'; | ||
if (currentUser){ | ||
let subscriptionStatus = null; | ||
let subscriptionCancelAt = null; | ||
let subscriptionID = null; | ||
@@ -42,21 +40,21 @@ const stripeCustomerResult = await stripe.customers.list({ | ||
if (subscriptionResult.data.length > 0){ | ||
subscriptionStatus = subscriptionResult.data[0].status; | ||
if (subscriptionResult.data[0].cancel_at) { | ||
subscriptionCancelAt = new Date(subscriptionResult.data[0].cancel_at * 1000) | ||
const subscription = subscriptionResult.data[0]; | ||
if (subscription.cancel_at) { | ||
subscriptionCancelAt = new Date(subscription.cancel_at * 1000) | ||
} | ||
subscriptionID = subscriptionResult.data[0].id; | ||
await locals.pb?.collection('users').update(userAuthSession.id, { | ||
subscriptionID: subscriptionStatus === "active" ? subscriptionID : null | ||
}) | ||
subscriptionID: subscription.status === "active" ? subscription.id : null | ||
}); | ||
} else { | ||
await locals.pb?.collection('users').update(userAuthSession.id, { | ||
subscriptionID: null | ||
}) | ||
}); | ||
} | ||
} | ||
if (currentUser.purchaseIntent) { | ||
let newUserState = {purchaseIntent: '', credits: currentUser.credits} | ||
const nonce = url.searchParams.get('nonce') | ||
const purchaseIntent = validateJwt(currentUser.purchaseIntent, VITE_NONCE_SIGNING_SECRET) as JwtPayload | ||
if (purchaseIntent && purchaseIntent.nonce === nonce) { | ||
const purchaseIntent = validateJwt(currentUser.purchaseIntent, VITE_NONCE_SIGNING_SECRET + nonce) as JwtPayload | ||
if (purchaseIntent) { | ||
newUserState = {...newUserState, credits: (currentUser.credits + purchaseIntent.credits)} | ||
@@ -67,2 +65,3 @@ } | ||
} | ||
return { | ||
@@ -69,0 +68,0 @@ loggedIn: locals.pb?.authStore.isValid, |
@@ -71,3 +71,3 @@ import jwt, { type JwtPayload } from 'jsonwebtoken'; | ||
const nonce = generateNonce(); | ||
const purchaseIntent = jwt.sign({...chosen, nonce}, VITE_NONCE_SIGNING_SECRET); | ||
const purchaseIntent = jwt.sign(chosen, VITE_NONCE_SIGNING_SECRET + nonce); | ||
const isProd = process.env.NODE_ENV === 'production' ? true : false; | ||
@@ -74,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
374996
420