Guest User

Untitled

a guest
Mar 15th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. const Session = require("supertokens-node/recipe/session")
  2. const ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword")
  3. const express = require("express")
  4. const cors = require("cors")
  5. const supertokens = require("supertokens-node")
  6. const { errorHandler, middleware } = require("supertokens-node/framework/express")
  7. const Dashboard = require("supertokens-node/recipe/dashboard")
  8.  
  9. let { Google, Github, Apple } = ThirdPartyEmailPassword;
  10.  
  11. supertokens.init({
  12. framework: "express",
  13. supertokens: {
  14. // https://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.
  15. // connectionURI: "https://try.supertokens.com",
  16. connectionURI: "http://localhost:3567",
  17. // apiKey: '5b2bc6ac-170f-4c16-90f6-81831e46b01e',
  18. },
  19. appInfo: {
  20. // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo
  21. appName: "shaggaga-buyer",
  22. apiDomain: "https://api-https-domain",
  23. websiteDomain: "https://frontend-domain",
  24. apiBasePath: "/",
  25. websiteBasePath: "/auth"
  26. },
  27. recipeList: [
  28. ThirdPartyEmailPassword.init({
  29. providers: [
  30. // We have provided you with development keys which you can use for testing.
  31. // IMPORTANT: Please replace them with your own OAuth keys for production use.
  32. Google({
  33. clientId: "$$ClientId",
  34. clientSecret : "$$clientSecret"
  35.  
  36.  
  37. }),
  38. ]
  39. }),
  40. Session.init({
  41. jwt: {
  42. enable: true,
  43. },
  44. override: {
  45. functions: function (originalImplementation) {
  46. return {
  47. ...originalImplementation,
  48. createNewSession: async function (input) {
  49. input.accessTokenPayload = {
  50. ...input.accessTokenPayload,
  51. "https://hasura.io/jwt/claims": {
  52. "x-hasura-user-id": input.userId,
  53. "x-hasura-default-role": "user",
  54. "x-hasura-allowed-roles": ["user"],
  55. }
  56. };
  57. return originalImplementation.createNewSession(input);
  58. },
  59. };
  60. }
  61. },
  62. }), // initializes session features
  63. Dashboard.init({
  64. apiKey: "$$apiKey"
  65. }),
  66.  
  67. ]
  68. });
  69.  
  70.  
  71. let app = express();
  72.  
  73. app.use(cors({
  74. origin: "https://frontend-domain",
  75. allowedHeaders: ["content-type", 'rid', 'fdi-version', 'anti-csrf', 'authorization', 'st-auth-mode'],
  76. methods: ["GET", "PUT", "POST", "DELETE"],
  77. credentials: true,
  78. }));
  79.  
  80. app.use(middleware());
  81.  
  82.  
  83. app.listen(10123, () => {
  84. console.log("Listening on port 10123");
  85. });
  86.  
Advertisement
Add Comment
Please, Sign In to add comment