I am Building a School management web app. My question is - Can i use one supertoken core for follo...
d
I am Building a School management web app. My question is - Can i use one supertoken core for following things 1. Managing Normal User Login (already using third-party password less login) 2. Staff Role Based Login eg. Teachers, Developers, Support team etc. 3. Student login If yes can anyone share docs for the same.
r
Hey @Dheeraj Bhandari
Are all these on the same app? Will these different types of users have different login methods?
d
No each one has seprate website. For staff login we have admin panel And for student login we have student website And for main website we have already implemented third-party password less login
r
Do each of these websites have their own backend? Or shared backend?
d
Have their own backend
Express Js back-end
@rp_st
r
right
so in that case, you can create an app in the core - one per app of yours, and then use that per backend. See this: https://supertokens.com/docs/multitenancy/new-app If you are using our managed core service, there should be a create new app button on the top right
d
So for each website i require seprate core ?
r
no. You can add new apps to an existing core
please see the link above
d
Ok sure
I have implemented multi aap. Can i get a docs how to add user using email password login and assign role to them.
d
I have successful created multitenancy in a supertoken core. it shows me becoz it was created before now i have updated it. But when i am trying to see url to check is response is Hello its sshowing "Not Found" for example http://localhost:3567/appid-mycreatedApp
r
you need to append the
/hello
path to the URL
d
oh ok thanks
supertokens.init({ framework: "express", supertokens: { connectionURI: process.env.SUPERTOKEN_CORE || "", apiKey: process.env.SUPERTOKEN_KEY || "", }, appInfo: { appName: "hackwiseAdmin", apiDomain:
${process.env.API_DOMAIN}
, websiteDomain:
${process.env.WEBSITE_DOMAIN}
, apiBasePath: "/auth", websiteBasePath: "/login" }, recipeList: [ EmailPassword.init(), // initializes signin / sign up features Session.init(), // initializes session features Dashboard.init(), ] }); this my supertoekn init function
r
Can you enable backend debug logs and show the output when this api is called?
d
[18/11/2023] [INFO] Error: not Found at P:\Github\Hackwise\admin panel\server\src\index.ts:96:23 at Layer.handle_error (P:\Github\Hackwise\admin panel\server\node_modules\express\lib\router\layer.js:71:5) at trim_prefix (P:\Github\Hackwise\admin panel\server\node_modules\express\lib\router\index.js:326:13) at P:\Github\Hackwise\admin panel\server\node_modules\express\lib\router\index.js:286:9 at Function.process_params (P:\Github\Hackwise\admin panel\server\node_modules\express\lib\router\index.js:346:12) at next (P:\Github\Hackwise\admin panel\server\node_modules\express\lib\router\index.js:280:10) at P:\Github\Hackwise\admin panel\server\node_modules\supertokens-node\lib\build\framework\express\framework.js:197:24 at Generator.throw () at rejected (P:\Github\Hackwise\admin panel\server\node_modules\supertokens-node\lib\build\framework\express\framework.js:36:44) at processTicksAndRejections (node:internal/process/task_queues:95:5) [18/11/2023] [INFO] Incoming -> Method: [GET] - Url: [/auth/signup/email/exists?email=asddfas] - IP: [::1] - Status: [null]
frontend
r
Can you enabler backend debug logs for supertokens?
And show that output?
d
This is the backend logs when api called
This is frontend log
pls help
r
as i said, please enable frontend and backend debug logs for supertokens and then show me
d
Not Able to Put debug log in backend
r
update to the latest backedn sdk
d
This is my superotken node version "supertokens-node": "^15.2.1",
r
and try again
or you can set the env var
DEBUG=com.supertokens
and then try
d
ok let me try
Done This my backend log
From frontend I a using checkEmail Fuction
r
you see a 500 error from the network call?
d
i am getting 404 Not found error
r
can i see the network tab?
d
r
hmm this is strange. The logs say that the requet is being handled, but you are seeing a 404
whats the backend framework that you are using?
d
Express JS
r
is it hitting your app's error handler?
d
i have implemented supertoken in one of my other project with passwordless but in this new project i am getting issue
yes
r
can i see the full error stack of the error that hits your error handler?
d
r
do other apis exposed by the backend sdk work?
like sign in?
d
No i just init the supertoken in backend Here it is // Super Token Init import supertokens from "supertokens-node"; import Session from "supertokens-node/recipe/session"; import EmailPassword from "supertokens-node/recipe/emailpassword"; import Dashboard from "supertokens-node/recipe/dashboard"; console.log(
${process.env.API_DOMAIN}
) console.log(
${process.env.WEBSITE_DOMAIN}
) supertokens.init({ framework: "express", supertokens: { connectionURI: process.env.SUPERTOKEN_CORE || "", apiKey: process.env.SUPERTOKEN_KEY || "", }, appInfo: { appName: "hackwiseAdmin", apiDomain:
${process.env.API_DOMAIN}
, websiteDomain:
${process.env.WEBSITE_DOMAIN}
, apiBasePath: "", websiteBasePath: "/" }, recipeList: [ EmailPassword.init(), // initializes signin / sign up features Session.init(), // initializes session features // Dashboard.init(), ] }); export default supertokens;
r
can you try calling the sign in API and seeing if that works?
or at leats if that doesn't return a 404
d
same with signin api
r
hmm
d
r
whats the connection uri you have set on the backend for the supertokens core?
d
When i try with postman with sending json body it is showing { "message": "Missing input param: formFields" } but when i send correct body it return { "message": "not Found" }
r
whats the connectio uri you have set on the backend/
r
the value of
process.env.SUPERTOKEN_CORE
d
This one
r
right ok
are you returning a 404 from your app's error handler?
d
yes
//error handler router.use(errorHandler()) router.use((err: any, req: Request, res: Response, next: NextFunction) => { const error = new Error('not Found'); Logging.error(error); return res.status(404).json({ message: error.message }) });
r
i see.
d
after all the routes
r
okay so for some reason, the core is saying not found
d
yes seems like
but dont know why so
r
which version of the backend sdk are you on again?
d
i am using same core which i have used in my previous project i just created a new aap with in the core
"supertokens-node": "^15.2.1",
"supertokens-node": "^15.2.1",
r
can you navigate to the supertokens-node lib code in node_modules and add a
console.log(finalURL.toString())
right before this line? https://github.com/supertokens/supertokens-node/blob/15.2/lib/build/querier.js#L232 And then tell me what it prints out when you call the email exists API
d
ok doing
r
thanks
d
added but it is not printing in console
sended req from frontend but still no console printing in backend
r
make sure that you have rebuilt the project and cleared cache, and restarted the backend server
d
i have changes current version supertoken from server and client to the version i have implemented in my previous project. Now everything is working fine
My Suggestion is it would be good if we should also show some logs when a successful connection established between server and backend so that user can know if all his configuration ifor supertoken is correct or not. Like we do for DB connection to ensure that it get connected before starting the server
r
makes sense.
What version are you using now?
d
backend "supertokens-node": "^12.1.6", Client "supertokens-auth-react": "^0.28.1", "supertokens-web-js": "^0.3.0",
r
hmmm. It should have worked with the version we gave as well. Perhaps @sattvikc can help investigate
s
I am trying to reproducing this myself, will get back on this soon
@Dheeraj Bhandari what was the frontend version u used with 15.2.1 ?
d
"react": "^18.2.0",
sure
s
not react. supertokens-auth-react
d
"supertokens-auth-react": "^0.35.1", "supertokens-web-js": "^0.8.0", This one Then i downgrade to "supertokens-auth-react": "^0.28.1", "supertokens-web-js": "^0.3.0", backend "supertokens-node": "^15.2.1", Then downgraded to "supertokens-node": "^12.1.6",
s
connectionURI
is same in both the cases ?
d
yes
no change in both frontend and backend env
27 Views