-
-
Save vktr/c6c99491f39349ac9b0547a9893837bf to your computer and use it in GitHub Desktop.
function (user, context, callback) { | |
user.app_metadata = user.app_metadata || {}; | |
if ('stripe_customer_id' in user.app_metadata) { | |
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id; | |
return callback(null, user, context); | |
} | |
var stripe = require('stripe')('sk_....'); | |
var customer = { | |
email: user.email | |
}; | |
stripe.customers.create(customer, function(err, customer) { | |
if (err) { | |
return callback(err); | |
} | |
user.app_metadata.stripe_customer_id = customer.id; | |
auth0.users.updateAppMetadata(user.user_id, user.app_metadata) | |
.then(function() { | |
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id; | |
callback(null, user, context); | |
}) | |
.catch(function(err) { | |
callback(err); | |
}); | |
}); | |
} |
Hey, very useful. Works like a charm
Thank you! 👏
What kind of info would replace example.com and stripe_customer_id (self explanatory, but I want to be sure) on the following line of code @vktr?
context.idToken['https://example.com/stripe_customer_id']
@YO-SC it is just used for namespacing so it can be anything, but I usually namespace my own claims under a domain I own.
@vktr Alright, I also forgot asking about this line:
var stripe = require('stripe')('sk_....');
What goes under the sk_...., is this a placeholder or is it used for namespacing as well ?
(Sorry for all the questions, I am fairly new to web development; at least in these type of scenarios)
@YO-SC that's where you put your Stripe secret key
@vktr Thanks for all the replies and support 👼 👍 😄
Have someone integrated it with their React, Node app. I want to see the actual implementation. I would be really thankful if anyone could share the working example. I hope you all will help me in this regard
What if I want it to look through all my stripe customers that have the same email address as the logged-in user and have it add the API ID of any active subscriptions to the users Auth0 app_metadata?
Hey thanks this is very helpful.