funk101
06/09/2022, 6:06 AMrp_st
06/09/2022, 6:06 AMfunk101
06/09/2022, 6:07 AMfunk101
06/09/2022, 6:09 AMfunk101
06/09/2022, 6:09 AMfunk101
06/09/2022, 6:12 AMSessionNode.init({
override: {
functions: async (originalImplementation) => {
return {
...originalImplementation,
createNewSession: async function (input) {
const stripeSellerId = await getStripeSellerIdBySuperTokensId(
input.userId
);
input.accessTokenPayload = {
...input.accessTokenPayload,
stripeSellerId: stripeSellerId,
};
return originalImplementation.createNewSession(input);
},
};
},
},
}),
funk101
06/09/2022, 6:13 AMfunk101
06/09/2022, 6:15 AMuseSessionContext
cause it's on the serverrp_st
06/09/2022, 6:20 AMSessionRequest
typing everywherewrp_st
06/09/2022, 6:20 AMreq.session.updateAccessTokenPayload
funk101
06/09/2022, 6:23 AMfunk101
06/09/2022, 6:23 AMrp_st
06/09/2022, 6:24 AMrp_st
06/09/2022, 6:24 AMfunk101
06/09/2022, 6:24 AMfunk101
06/09/2022, 6:24 AMexport default async function handler(req, res) {
const userId = req.body;
const email = await getUserEmailBySuperTokensId(userId);
await superTokensNextWrapper(
async (next) => {
await verifySession()(req, res, next);
},
req,
res
);
const currentAccessTokenPayload = req.session.getAccessTokenPayload();
funk101
06/09/2022, 6:25 AMawait superTokensNextWrapper...
funk101
06/09/2022, 6:25 AMrp_st
06/09/2022, 6:26 AMrp_st
06/09/2022, 6:26 AMrp_st
06/09/2022, 6:26 AMreq.session
object.funk101
06/09/2022, 6:31 AMauth/[[...path]].js
, doesn't matter right? That code can be used where ever needed I guessrp_st
06/09/2022, 6:32 AMrp_st
06/09/2022, 6:32 AMfunk101
06/09/2022, 6:32 AMsupertokens.init(backendConfig());
export default async function superTokens(req, res) {
// NOTE: We need CORS only if we are querying the APIs from a different origin
await NextCors(req, res, {
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: process.env.NEXT_PUBLIC_HOST,
credentials: true,
allowedHeaders: ["content-type", ...supertokens.getAllCORSHeaders()],
});
await superTokensNextWrapper(
async (next) => {
await middleware()(req, res, next);
},
req,
res
);
if (!res.writableEnded) {
res.status(404).send("Not found");
}
}
funk101
06/09/2022, 6:32 AMrp_st
06/09/2022, 6:32 AMauth/[[...path]].js
file should remain the same.. no need to change thatfunk101
06/09/2022, 6:33 AMrp_st
06/09/2022, 6:33 AMfunk101
06/09/2022, 6:33 AMfunk101
06/09/2022, 3:11 PMrp_st
06/09/2022, 3:11 PMrp_st
06/09/2022, 3:11 PMfunk101
06/09/2022, 3:12 PMfunk101
06/09/2022, 3:12 PMsignInPOST: async function (input) {
if (originalImplementation.signInPOST === undefined) {
throw Error("Shouldn't come here")
}
try {
const response = await originalImplementation.signInPOST(input)
if (response.status === "OK") {
const {id, email} = response.user
}
}
}
rp_st
06/09/2022, 3:12 PMrp_st
06/09/2022, 3:12 PMresponse.session
funk101
06/09/2022, 3:12 PMfunk101
06/09/2022, 3:13 PMfunk101
06/09/2022, 3:13 PMrp_st
06/09/2022, 3:13 PMawait response.session.updateAccessTokenPayload({..})
rp_st
06/09/2022, 3:13 PMresponse.status === "OK"
funk101
06/09/2022, 3:13 PMfunk101
06/09/2022, 3:26 PMerror - TypeError: Cannot read properties of undefined (reading 'status')
but if I refresh browser it goes through and I see what I need to seefunk101
06/09/2022, 3:26 PMsignInPOST: async function (input) {
if (originalImplementation.signInPOST === undefined) {
throw Error("Shouldn't come here");
}
try {
const response = await originalImplementation.signInPOST(
input
);
if (response.status === "OK") {
const { id, email } = response.user;
const stripeSellerId =
await getStripeSellerIdBySuperTokensId(id);
if (stripeSellerId) {
const currentAccessTokenPayload =
response.session.getAccessTokenPayload();
await response.session.updateAccessTokenPayload({
...currentAccessTokenPayload,
stripeSellerId: stripeSellerId,
});
}
}
} catch (err) {
serverLogger.error("/config/backendConfig: ", err.message);
}
},
rp_st
06/09/2022, 3:27 PMfunk101
06/09/2022, 3:28 PMrp_st
06/09/2022, 3:29 PMrp_st
06/09/2022, 3:29 PMrp_st
06/09/2022, 3:29 PMfunk101
06/09/2022, 3:30 PMfunk101
06/09/2022, 3:30 PMrp_st
06/09/2022, 3:31 PMrp_st
06/09/2022, 3:31 PMresponse
from the overridefunk101
06/09/2022, 3:31 PMrp_st
06/09/2022, 3:31 PMcatch
part, you need to do return response
funk101
06/09/2022, 3:35 PMfunk101
06/09/2022, 3:36 PMfunk101
06/09/2022, 3:36 PMrp_st
06/09/2022, 3:37 PMfunk101
06/09/2022, 3:37 PMrp_st
06/09/2022, 3:37 PMrp_st
06/09/2022, 3:38 PMfunk101
06/09/2022, 3:38 PM