funk101
06/09/2022, 6:06 AMrp
06/09/2022, 6:06 AMfunk101
06/09/2022, 6:07 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);
},
};
},
},
}),
useSessionContext
cause it's on the serverrp
06/09/2022, 6:20 AMSessionRequest
typing everywherewreq.session.updateAccessTokenPayload
funk101
06/09/2022, 6:23 AMrp
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();
await superTokensNextWrapper...
rp
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
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");
}
}
rp
06/09/2022, 6:32 AMauth/[[...path]].js
file should remain the same.. no need to change thatfunk101
06/09/2022, 6:33 AMrp
06/09/2022, 6:33 AMfunk101
06/09/2022, 6:33 AMrp
06/09/2022, 3:11 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
06/09/2022, 3:12 PMresponse.session
funk101
06/09/2022, 3:12 PMrp
06/09/2022, 3:13 PMawait response.session.updateAccessTokenPayload({..})
response.status === "OK"
funk101
06/09/2022, 3:13 PMerror - TypeError: Cannot read properties of undefined (reading 'status')
but if I refresh browser it goes through and I see what I need to seesignInPOST: 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
06/09/2022, 3:27 PMfunk101
06/09/2022, 3:28 PMrp
06/09/2022, 3:29 PMfunk101
06/09/2022, 3:30 PMrp
06/09/2022, 3:31 PMresponse
from the overridefunk101
06/09/2022, 3:31 PMrp
06/09/2022, 3:31 PMcatch
part, you need to do return response
funk101
06/09/2022, 3:35 PMrp
06/09/2022, 3:37 PMfunk101
06/09/2022, 3:37 PMrp
06/09/2022, 3:37 PMfunk101
06/09/2022, 3:38 PM