Hi, I want to appned a redirect Url in the magicLink based on the url from which user has come for a...
a
Hi, I want to appned a redirect Url in the magicLink based on the url from which user has come for authentication , so how can i get that extra parameter from the frontend so that i can alter the magicLink. we are using both FE and BE supertoken sdk. For appending url in the magic link i will be using the sendRawEmail function and override it, but url that is to be appended is not fix, it should depend on some value that will be coming from frontend. so how can i pass from frontend and get at backend. I am using THIRDPARTY_PASSWORDLESS
r
hey @anurag06557
you can pass that url from the frontend when calling the consumeCode API as a custom prop in the request body, and then read that on the backend in the sendRawEmail function from the userContext
a
Hi, @rp_st ,, I am using this function to pass extra parameters from frontend in createPasswordLessCode
Copy code
async function sendMagicLink() {
    setIsDisableButton(true);
    const responsePayload =
      tab === DECCAN_MOBILE_TAB
        ? { phoneNumber: `+91${formData.phone}` }
        : { email: formData.email };
    const errMsg =
      tab === DECCAN_MOBILE_TAB ? "Invalid phone number" : "Invalid email";
    const infoMsg = tab === DECCAN_MOBILE_TAB ? INFO_MSG_PHONE : INFO_MSG_EMAIL;
    const userContext = {
        redirectUrl:callbackUrl
    }
    if (formData.phone || formData.email) {
      try {
        let response = await createPasswordlessCode(responsePayload,{callbackUrl});
now i want this callbackUrl thing in emailDelivery section where i need to append this callbackUrl as queryParam in the magic Link, how can i do this , i am trying to overRide emailDelivery function in the backend.
Copy code
ThirdPartyPasswordless.init({
    emailDelivery: {
      service: new SMTPService({
        smtpSettings,
        override: (originalImplementation) => {
          return {
            ...originalImplementation,
            getContent: async function (input) {
         
              const userContext = getRequestFromUserContext(input.userContext)
     
              const magicLinkUrl = input.urlWithLinkCode + userContext["callbackUrl"]
             
              const originalContent = await originalImplementation.getContent(
                input,
              );
please suggest as i am not getting the value at backend
r
well, see the type of object returned from
getRequestFromUserContext
a
am i doing anything wrong here?
this is the response we are getting from getRequestFromUserCOntext(input.userContext)
Copy code
userContext: ExpressRequest {
    wrapperUsed: true,
    getFormData: [AsyncFunction (anonymous)],
    getKeyValueFromQuery: [Function (anonymous)],
    getJSONBody: [AsyncFunction (anonymous)],
    getMethod: [Function (anonymous)],
    getCookieValue: [Function (anonymous)],
    getHeaderValue: [Function (anonymous)],
    getOriginalURL: [Function (anonymous)],
    original: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: null,
      aborted: false,
      upgrade: false,
      url: '/auth/signinup/code',
      method: 'POST',
      statusCode: null,
      statusMessage: null,
      client: [Socket],
      _consuming: true,
      _dumped: false,
      next: [Function: next],
      baseUrl: '',
      originalUrl: '/auth/signinup/code',
      _parsedUrl: [Url],
      params: {},
      query: {},
      res: [ServerResponse],
      body: [Object],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 40,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    

    parserChecked: true,
    formDataParserChecked: false
  }
}
r
yup!
so you can call the functions from it
it's there in our docs
a
I am getting undefined when trying to do this
Copy code
const callbackUrl = userContext.getHeaderValue("callbackUrl")
what i am trying to do , can it be done, like passing context in createPasswordlessCode() from frontend and in backend using that in emailDelivery part?
r
yea
a
still getting undefined here, am i passing correctly from Frontend?
r
you have to use our pre api hook on the frontend to add the custom header
see our docs please. The link shared above
a
why are we getting frequeent error as ERR_NAME_NOT_RESOLVED , while creating code api
r
whats the full stack trace?
14 Views