mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-06-14 08:58:22 +02:00
Add pairing code support to provisioning API
This commit is contained in:
parent
4efb226045
commit
f8a22aab06
|
@ -684,6 +684,7 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
qrChan, err := user.Login(ctx)
|
||||
expiryTime := time.Now().Add(160 * time.Second)
|
||||
if err != nil {
|
||||
user.log.Errorln("Failed to log in from provisioning API:", err)
|
||||
if errors.Is(err, ErrAlreadyLoggedIn) {
|
||||
|
@ -699,6 +700,25 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
}
|
||||
}
|
||||
phoneNum := r.URL.Query().Get("phone_number")
|
||||
if phoneNum != "" {
|
||||
pairingCode, err := user.Client.PairPhone(phoneNum, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
|
||||
if err != nil {
|
||||
user.zlog.Err(err).Msg("Failed to start phone code login")
|
||||
_ = c.WriteJSON(Error{
|
||||
Error: "Failed to request pairing code",
|
||||
ErrCode: "code error",
|
||||
})
|
||||
go user.DeleteConnection()
|
||||
return
|
||||
} else {
|
||||
_ = c.WriteJSON(map[string]any{
|
||||
"pairing_code": pairingCode,
|
||||
"timeout": int(time.Until(expiryTime).Seconds()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
user.log.Debugln("Started login via provisioning API")
|
||||
Analytics.Track(user.MXID, "$login_start")
|
||||
|
||||
|
|
Loading…
Reference in a new issue