birdinadream
08/01/2022, 7:56 AMrp_st
08/01/2022, 8:04 AMbirdinadream
08/01/2022, 8:06 AMbirdinadream
08/01/2022, 8:06 AMconst SuperTokensComponentNoSSR = dynamic(new Promise((res) => res(SuperTokens.getRoutingComponent)) as any, {
ssr: false
});
const AuthPage: NextPageWithLayout = () => {
useEffect(() => {
if (SuperTokens.canHandleRoute() === false) {
redirectToAuth();
}
}, []);
//@ts-ignore;
return <SuperTokensComponentNoSSR />;
};
AuthPage.getLayout = function getLayout(page) {
return (
<Container>
<img src="/navawalogo.svg" alt="Natuurbegraafplaatsen van waarde" />
<article>{page}</article>
</Container>
);
};
rp_st
08/01/2022, 8:07 AMbirdinadream
08/01/2022, 8:08 AMrp_st
08/01/2022, 8:10 AM<SuperTokensComponentNoSSR />
component when google redirects you back, that will call the signinup API twice, and the second call will fail.rp_st
08/01/2022, 8:10 AMbirdinadream
08/01/2022, 8:12 AMbirdinadream
08/01/2022, 8:15 AM//code to check user
if (user !== null) {
return await originalImplementation.signInUp(input);
}
rp_st
08/01/2022, 8:15 AMbirdinadream
08/01/2022, 8:16 AMrp_st
08/01/2022, 8:16 AMrp_st
08/01/2022, 8:23 AMawait originalImplementation.signInUp(input);
even if a user is not allowed to sign up? Can I see the whole override implementation?birdinadream
08/01/2022, 8:28 AMimport ThirdPartyNode from "supertokens-node/recipe/thirdparty";
import SessionNode from "supertokens-node/recipe/session";
import { appInfo } from "./appInfo";
import { TypeInput } from "supertokens-node/types";
import { getUserByThirdPartyUserID, getUserByEmail } from "lib/db/query";
export const backendConfig = (): TypeInput => {
return {
framework: "express",
supertokens: {
// try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
connectionURI: process.env.AUTH_SERVER || ""
// apiKey: "IF YOU HAVE AN API KEY FOR THE CORE, ADD IT HERE",
},
appInfo,
recipeList: [
ThirdPartyNode.init({
signInAndUpFeature: {
providers: [
// We have provided you with development keys which you can use for testsing.
// IMPORTANT: Please replace them with your own OAuth keys for production use.
ThirdPartyNode.Google({
clientId: process.env.GOOGLE_ID || "",
clientSecret: process.env.GOOGLE_SECRET || ""
})
]
},
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
signInUp: async (input) => {
console.log("Check if should signup", input.email.id);
let user = await getUserByEmail(input.email.id);
if (user !== null) {
return await originalImplementation.signInUp(input);
}
throw new Error("Not allowed to signup");
}
};
},
apis: (originalImplementation) => {
return {
...originalImplementation
// signInUpPOST: undefined
};
}
}
}),
SessionNode.init({
jwt: {
enable: true
},
override: {
functions: function (originalImplementation) {
return {
...originalImplementation,
createNewSession: async function (input) {
let user = await getUserByThirdPartyUserID(input.userId);
if (!user || !user.is_active) {
throw new Error("User not found");
}
input.accessTokenPayload = {
...input.accessTokenPayload,
"https://hasura.io/jwt/claims": {
"x-hasura-user-id": input.userId,
"x-hasura-default-role": user.is_admin ? "admin" : "user",
"x-hasura-allowed-roles": user.is_admin ? ["admin", "user"] : ["user"]
}
};
return originalImplementation.createNewSession(input);
}
};
}
}
})
]
};
};
rp_st
08/01/2022, 8:29 AMrp_st
08/01/2022, 8:29 AMbirdinadream
08/01/2022, 8:30 AMbirdinadream
08/01/2022, 8:30 AMrp_st
08/01/2022, 8:35 AMbirdinadream
08/01/2022, 8:38 AMrp_st
08/01/2022, 8:42 AMrp_st
08/01/2022, 8:42 AMbirdinadream
08/01/2022, 8:58 AMrp_st
08/01/2022, 9:02 AMbirdinadream
09/02/2022, 10:49 AMrp_st
09/02/2022, 10:51 AMbirdinadream
09/22/2022, 8:24 AMrp_st
09/22/2022, 8:25 AMrp_st
09/22/2022, 8:25 AMbirdinadream
09/22/2022, 8:34 AMrp_st
09/22/2022, 8:34 AMbirdinadream
09/22/2022, 8:34 AMThirdPartyNode.init({
signInAndUpFeature: {
providers: [
// We have provided you with development keys which you can use for testsing.
// IMPORTANT: Please replace them with your own OAuth keys for production use.
ThirdPartyNode.Google({
clientId: process.env.GOOGLE_ID || "",
clientSecret: process.env.GOOGLE_SECRET || ""
})
]
},
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
signInUp: async (input) => {
console.log("Check if should signup", input.email.id);
let user = await getUserByEmail(input.email.id);
if (user !== null) {
return await originalImplementation.signInUp(input);
}
throw new Error("Not allowed to signup");
}
};
},
apis: (originalImplementation) => {
return {
...originalImplementation
// signInUpPOST: undefined
};
}
}
}),
birdinadream
09/22/2022, 8:35 AMrp_st
09/22/2022, 8:36 AMgetUserByEmail
function from?birdinadream
09/22/2022, 8:36 AMrp_st
09/22/2022, 8:37 AMbirdinadream
09/22/2022, 8:37 AMrp_st
09/22/2022, 8:38 AMrp_st
09/22/2022, 8:38 AMbirdinadream
09/22/2022, 8:38 AMrp_st
09/22/2022, 8:39 AMbirdinadream
09/22/2022, 8:39 AMrp_st
09/22/2022, 8:40 AMrp_st
09/22/2022, 8:40 AMbirdinadream
09/22/2022, 8:41 AMbirdinadream
09/22/2022, 8:42 AMrp_st
09/22/2022, 8:43 AMrp_st
09/22/2022, 8:43 AMbirdinadream
09/22/2022, 8:44 AMrp_st
09/22/2022, 8:45 AMbirdinadream
09/22/2022, 8:45 AMrp_st
09/22/2022, 8:45 AMbirdinadream
09/22/2022, 8:46 AMrp_st
09/22/2022, 8:48 AMbirdinadream
09/22/2022, 8:49 AMrp_st
09/22/2022, 8:49 AMbirdinadream
09/27/2022, 1:44 PMrp_st
09/27/2022, 1:45 PM