Im trying to call the backend api using a vanilla axios. I’ve added rid in the headers, and attempti...
c
Im trying to call the backend api using a vanilla axios. I’ve added rid in the headers, and attempting to POST a json object of formfields with an array of objects - email and password (just like how the testing with postman section has specified). However, I keep getting an error when attempting to POST. Essentially I’m trying to create a user without using the sign in/up form. Am I missing some headers etc?
r
Hey!
What’s the error? Also, you should use our axios interceptors
c
I did use the interceptors
Do you have an example where I can use axios to POST to signup without using the SignInAndUp component?
r
Well, the supertokens-auth-react SDK exposes several helper functions that you can use. One of them is the signUp function, for example from the emailpassword recipe, there is EmailPassword.signUp
Use that instead of manually calling via axios. Will be easier
c
Any docs on that?
What arguments do I need to pass to the function in what form etc
r
No docs yet. Working on it.
But it takes the form field array
So pass the email and password
As two different form fields
With id “email” and “password”
c
just like Postman right?
Any headers required?
r
Copy code
await EmaiPassword.signUp({
  formFields: [{
    id: "email",
    value: "..."
  }, {
    id: "password",
    value: "..."
  }]
})
no special headers required.. the SDK figures it out
c
Sounds good I’ll try it
Thank you
Hi, it seems like doing that will set the cookies. Is there a way to simply create users? I am building an admin panel. So what I need is only for it to create the users,.
r
ah ok. In that case, you want to create your own API on the backend which has admin auth as a guard for it, and in that API, call the
EmailPassword.signUp(email, password)
function from the backend SDK. This will just create the user in supertokens without creating cookies.
c
Im using python fastapi for the backend
What is the equivalent of EmailPassword.signUp(email, password)?
r
There should be emailpassword.syncio.sign_up
Or emailpassword.asyncio.sign_up
c
Does it return the created user?
r
It does
See the reference here supertokens.com/docs/python
c
It gives me back EmailPasswordSignUpOkResult
r
Yea. That’s a class which contains the info about the user
c
Is there a way where I can see the keys and values of this object?
If I print it, it just prints an object in memory
r
See the reference link I sent above.
c
This is all I can find
r
Ouu I see. It’s not explicitly defined in the func signature.
c
Thank you
I was also able to print it out using this
Copy code
from pprint import pprint

    pprint(vars(data))
r
Ah fair enough
c
@rp_st emailpassword.syncio.sign_up does not call the post sign up actions that I have defined right?
r
Well, if the post sign up callback is in the apis config, it wont. If it’s in the functions config, it will
c
I have added some actions to be taken upon signing up. It works if I use the form, but not for emailpassword.syncio.sign_up (which is fine)
Can you clarify
I did it the way the docs did
which one is that
r
Yea. The docs says about APIs
So the api override only affects the api call
The function override affects api and functional calls.
If you see the override config, it has two params, apis and functions
Also, apis can call multiple functions. For example the sign up api will call the sign_up function (which you are trying to use above) and the create_new_session function from the session recipe.
Whereas the functions override only affects that individual function and nothing else.
c
Copy code
async def emailpassword_sign_up_post(form_fields: List[FormField],
                                         api_options: EmailPasswordAPIOptions, user_context: Dict[str, Any]):
        # call the default behaviour as show below
        result = await original_emailpassword_sign_up_post(form_fields, api_options, user_context)

        if isinstance(result, EmailPasswordSignUpPostOkResult):
            pass # TODO: some post sign up logic
        
        return result
Is this the "function"?
r
No. This is api override
There is a section in override section called backend function override. See that
c
So if I add a post sign up action in api override, it will only be called using the form. Or if I POST to "{apiBaserPath}/auth/signup".
If I use emailpassword.syncio.sign_up, the post sign up will NOT work.
Correct?
However, if I override the emailpassword.syncio.sign_up (as specified in https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/backend-functions-override/usage), whenever I call emailpassword.syncio.sign_up or POST to "{apiBaserPath}/auth/signup", they will both call the POST sign up function since the api calls the function
Does that sound right?
r
Correct! Exactly
c
Thanks rp
Do you know why I wasnt able to POST using axios?
it gives me a 400 error
r
Well, maybe you didn’t add the correct headers for content type
c
Where can I find all the right headers?
I did add rid="thirdpartyemailpassword"
r
Well, just that and content-type=“application/json”
c
ok I will try again