# AuthService.socialSignin custom logic

```ts
/* --------------------------- start custom logic --------------------------- */
const { data } = body;
if (!data?.provider)
  throw new exceptions.UnprocessableEntityException("Provider is required");
if (!data?.id_token)
  throw new exceptions.UnprocessableEntityException("Token is required");
const decoded = await initializeFirebase().auth.verifyIdToken(data.id_token);
if (!decoded) throw new exceptions.UnauthorizedException("Invalid token");
scenario.set("decoded", decoded);

let doc = await this.federatedCredentialModel.findOne({
  "firebase_data.uid": decoded.uid,
});

if (!doc) {
  const fedDocData: Partial<Jsm.Core.Auth.Entity.FederatedCredential> = {
    account_linking_status: "pending",
    firebase_data: decoded,
  };
  doc = await this.federatedCredentialModel.create(fedDocData);
}

if (doc) {
  const [first_name, ...restWords] = ((decoded.name as string) || "").split(
    " "
  );

  const signupPayload: Jsm.Core.Auth.Api.Auth.Signup.Request["data"] = {
    email: decoded.email ?? decoded.phone_number,
    name: decoded.name ?? "",
    meta: {
      first_name: first_name,
      family_name: restWords.join(" "),
      photo: {
        url: decoded.picture,
      },
      phones: decoded.phone_number,
    },
  };
  scenario.set("signup", signupPayload);

  if (doc.user_id) {
    try {
      const signinResult = await this.signinWithId(
        {
          data: {
            user_id: doc.user_id,
          },
        },
        undefined,
        {
          bypassAuthorization: true,
        }
      );

      result.data = {
        ...signinResult.data,
        is_new: false,
      };
    } catch (error) {
      if (error.status === 400) {
        const signupResult = await this.signup({
          data: signupPayload,
        });
        result = {
          data: {
            ...signupResult.data,
            is_new: true,
          },
        };

        doc.user_id = signupResult.data?.user._id;
        await doc.save();
      }
    }
  } else {
    // create new user
    const signupResult = await this.signup({
      data: signupPayload,
    });
    result.data = {
      ...signupResult.data,
      is_new: true,
    };

    doc.user_id = signupResult.data?.user._id;
    await doc.save();
  }
} else
  throw new exceptions.InternalServerError(
    "Could not create federated credential"
  );
/* ---------------------------- end custom logic ---------------------------- */
```
