Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
740 B

package Auth
import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
)
type deviceToken struct {
Token string `json:"token"`
Type string `json:"type"`
}
func AddDeviceToken(w http.ResponseWriter, r *http.Request) {
var (
token deviceToken
userToken Database.DeviceToken
err error
)
err = json.NewDecoder(r.Body).Decode(&token)
if err != nil {
http.Error(w, "Error", http.StatusInternalServerError)
return
}
userToken = Database.DeviceToken{
Token: token.Token,
DeviceType: token.Type,
}
err = (&userToken).CreateUserDeviceToken()
if err != nil {
http.Error(w, "Error", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
}