-
Notifications
You must be signed in to change notification settings - Fork 167
Description
Describe the bug A clear and concise description of what the bug is.
When I create or delete a subscription, I sometimes need to logout and log back in before the subscription will take effect.
To Reproduce Steps to reproduce the behavior:
- Follow the instructions in the README to setup this project with Github Auth and Stripe.
- Upgrade your account
- Go to the
/accountpage and see that the subscription has not updated. - Log out, log back in, head to
/account, and see that your subscription has updated.
Sometimes, you'll not see the subscription being upgraded. I'm not sure why it's only sometimes.
The same thing occurs for me when I cancel a subscription. I also need to log out and in to see the change reflected.
Expected behavior A clear and concise description of what you expected to
happen.
I expect the subscription status to be updated.
Desktop (please complete the following information):
- OS: iOS
- Browser: Arc (Chromium based), Safari
- Version 1.60.0, 17.6 (19618.3.11.11.5)
Additional context Add any other context about the problem here.
I added logging statements in routes/api/stripe-webhooks.ts and plugins/session.ts to see what's going on.
It seems that the session ID is different. I suspect the request has the old session ID.
customer.subscription.deleted - user = {
login: "RealScrappyDev",
sessionId: "7940bacf-9e00-4238-80b1-079c72e8eab8",
isSubscribed: false,
stripeCustomerId: "cus_QqYvnSqI1OeGqo"
}
setSessionState - user = {
login: "RealScrappyDev",
sessionId: "3651b8e0-ba96-4065-89a6-5a1f1d2f7ad2",
isSubscribed: true,
stripeCustomerId: "cus_QqYvnSqI1OeGqo"
}
I can work around this by using the session ID to get the user's login and then getting the user from there, but this doesn't seem ideal. Specifically, this works for me in plugins/session.ts's setSessionState function:
const sessionId = getSessionId(req);
if (sessionId === undefined) return await ctx.next();
const user = await getUserBySession(sessionId);
if (user === null) return await ctx.next();
const latestUser = await getUser(user.login);
if (latestUser === null) return await ctx.next();
ctx.state.sessionUser = latestUser;It is definitely possible that I'm doing something wrong here. I've tried to start fresh with a new database and stripe init.