Make a LOGIN SYSTEM for your UNITY GAME | Full Stack Unity & ASP Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

ความคิดเห็น • 36

  • @tutorialsEU
    @tutorialsEU  2 ปีที่แล้ว +2

    🎮 Unity Masterclass - Master game development by building enjoyable games from scratch: bit.ly/3YJWe0N

  • @christianstamati
    @christianstamati 2 ปีที่แล้ว +2

    Hello thanks a lot for the video! In my case we used the same approach we have multiple API services and the unity app is talking with them. I saw that in your project you used a simple singleton for the object that is calling the API. Do you know if there is a better way to implement the service on the frontend? Because we used singletons to and now its really impossible to test without the DB. Thanks!!

  • @ДмитрийНечепуренко-т7д
    @ДмитрийНечепуренко-т7д ปีที่แล้ว

    In you user registration you may have dublicates in your database

  • @AxisMundiOnline
    @AxisMundiOnline ปีที่แล้ว +1

    Supremely helpful tutorial/ Thanks.

  • @coldkiller6653
    @coldkiller6653 2 ปีที่แล้ว +3

    At 33:55 in the video, when I press register I get an error message {"Message":"The request is invalid.","ModelState":{"model.Email":["The Email field is required."]}, anyone have any idea what I could be doing wrong and how to fix this?

    • @pan1k524
      @pan1k524 2 ปีที่แล้ว

      hey! have you resolved the issue?

    • @pan1k524
      @pan1k524 2 ปีที่แล้ว

      I have the same one and don't know what to do (:

    • @ethanohmer
      @ethanohmer 2 ปีที่แล้ว

      Did anyone ever find the solution to this?

    • @coldkiller6653
      @coldkiller6653 2 ปีที่แล้ว

      @@pan1k524 nope couldn't work it out

    • @trackMythoughts
      @trackMythoughts ปีที่แล้ว

      string jsonData = JsonUtility.ToJson(register); this code removes Email and only save password and confirm password into byte array, that is the reason you are getting the error.

  • @chefi5357
    @chefi5357 ปีที่แล้ว

    Hey I know it's an old video but do you have any idea why JsonUtility.ToJson doesn't work with the shorthand getters and setters. If I delete them and only declare the properties the class should have, without getters and setters, then JsonUtility.ToJson works fine.

  • @zohansworld8039
    @zohansworld8039 2 ปีที่แล้ว +1

    When saving the data I get this message:
    "Message":"Authorization has been denied for this request.
    form.headers.Add("Authorization", "Bearer "+ login.access_token);
    UnityWebRequest webRequest = UnityWebRequest.Post(baseURL + "api/userprofile", form);
    How to solve?

    • @ethanohmer
      @ethanohmer 2 ปีที่แล้ว +2

      I had this same issue, and it turned out to be the way the UnityWebRequest Register() method was sending data with the json utility. To fix this I changed it to also be a WWWForm as follows:
      public IEnumerator Register(Register register)
      {
      WWWForm form = new WWWForm();
      form.AddField("Email", emailInputField.text);
      form.AddField("username", emailInputField.text);
      form.AddField("password", passwordInputField.text);
      form.AddField("password_confirmation", confirmPasswordInputField.text);
      UnityWebRequest uwr = UnityWebRequest.Post(baseUrl + "/api/Account/Register", form);

      yield return uwr.SendWebRequest();
      if (uwr.result == UnityWebRequest.Result.ConnectionError)
      {
      Debug.Log("Error" + uwr.error);
      }
      else
      {
      Debug.Log(uwr.downloadHandler.text);
      }
      I will also post my LogIn() and SaveData() methods to help incase you end up needing them too. A couple things to note, in the LogIn method it didnt make much sense to call the SaveData() coroutine since in general people want to load character data while logging in so, thus I added that to mine. Also make sure to either add or remove the "api/" from your base url depending on how you particularly implement the code or what else youre adding to the string.
      public IEnumerator LogIn()
      {
      WWWForm form = new WWWForm();
      form.AddField("grant_type", "password");
      form.AddField("Email", loginEmailInputField.text);
      form.AddField("username", loginEmailInputField.text);
      form.AddField("password", loginPasswordInputField.text);
      UnityWebRequest uwr = UnityWebRequest.Post( baseUrl +"token", form);

      yield return uwr.SendWebRequest();
      if (uwr.result == UnityWebRequest.Result.ConnectionError )
      {
      Debug.Log("Error" + uwr.error);
      }
      else
      {
      Debug.Log(uwr.downloadHandler.text);
      logIn = JsonUtility.FromJson(uwr.downloadHandler.text);
      //Debug.Log(logIn.access_token.ToString());
      //StartCoroutine(SaveData());
      //StartCoroutine(LoadData());
      }
      }
      Finally here is the SaveData() method:
      public IEnumerator SaveData()
      {
      WWWForm form = new WWWForm();
      form.AddField("Email", email);
      form.AddField("username", email);
      form.AddField("UserData", "some string of information such as item id or whatever you want");
      //Debug.Log(logIn.access_token);

      UnityWebRequest uwr = UnityWebRequest.Post(baseUrl = "/API/UserProfile", form);
      uwr.SetRequestHeader("Authorization", "Bearer " + logIn.access_token);
      yield return uwr.SendWebRequest();
      if (uwr.result == UnityWebRequest.Result.ConnectionError)
      {
      Debug.Log("Error" + uwr.error);
      }
      else
      {
      Debug.Log(uwr.downloadHandler.text);
      }
      }

    • @zohansworld8039
      @zohansworld8039 2 ปีที่แล้ว

      @@ethanohmer Thanks for the solution :)

  • @teoprod
    @teoprod 2 ปีที่แล้ว

    AWESOME MAN! Is there a way where the user only gets logged in successfully if the owner of the firebase (in the case, me) accepts the login?

  • @R0W1N
    @R0W1N 2 ปีที่แล้ว

    Question, you've used the column 'UserData' but where exactly are you filling the information from that field when creating the user? Because mine is empty, where as other columns as username and password are filled in correctly.

  • @zohansworld8039
    @zohansworld8039 2 ปีที่แล้ว

    The Get and Post method written in UserProfileController donot work. Wrong

  • @busrayuksel2113
    @busrayuksel2113 2 ปีที่แล้ว

    Hi, Im trying to create azure app service, what should i do as runtime stack? .

  • @talismanskulls2857
    @talismanskulls2857 ปีที่แล้ว

    How to integrate character select?

  • @ethanohmer
    @ethanohmer 2 ปีที่แล้ว

    I keep getting an "Authorization has been denied for this request." after attempting to implement the SaveData(). Any ideas?

    • @ethanohmer
      @ethanohmer 2 ปีที่แล้ว +1

      I found the solution. Still not sure why the method shown was not working, but in the SaveData() method, it is no longer:
      form.AddField("username", loginEmailInputField.text);
      form.AddField("UserData", "{score:15}");
      form.headers.Add("Authorization", "Bearer " + logIn.access_token);
      UnityWebRequest uwr = UnityWebRequest.Post(baseURL + "API/UserProfile", form);
      Instead, it should be as follows:
      form.AddField("username", loginEmailInputField.text);
      form.AddField("UserData", "{score:15}");
      UnityWebRequest uwr = UnityWebRequest.Post(baseURL + "API/UserProfile", form);
      uwr.SetRequestHeader("Authorization", "Bearer " + logIn.access_token);
      Hopefully this can save some poor soul the hours it took me to brute force this solution haha.

    • @harrybuscema1582
      @harrybuscema1582 2 ปีที่แล้ว

      @@ethanohmer hi mate, did you find a solution to the {"Message":"The request is invalid.","ModelState":{"model.Email":["The Email field is required."]} error?

    • @ethanohmer
      @ethanohmer 2 ปีที่แล้ว

      @@harrybuscema1582 make sure to add:
      form.AddField("Email", email);
      form.AddField("username", email);
      to both the Register(), SaveData(), and LogIn() methods. I had to end up using WWWForm for all three to properly send data. Also, when logging in, the username must be an email.

    • @ethanohmer
      @ethanohmer 2 ปีที่แล้ว

      I just added my full methods to the user "Zohan's world" comment down below which may also be useful to you. If you're still unable to get it working I would be open to helping further over discord or something so you can stream and work through the issue.

    • @harrybuscema1582
      @harrybuscema1582 2 ปีที่แล้ว

      @@ethanohmer yep thanks so much mate, life saver, worked perfectly!

  • @brandonkeller16
    @brandonkeller16 ปีที่แล้ว

    token wont output for me

  • @KasSanity
    @KasSanity ปีที่แล้ว

    I always get this debug when trying to register. Is there an slightly updated version or something simply wrong?
    {"Message":"The request is invalid.","ModelState":{"model.Email":["The Email field is required."],"model.Password":["The Password field is required."]}}
    UnityEngine.Debug:Log (object)
    NetworkingManager/d__16:MoveNext () (at Assets/Scripts/NetworkingManager.cs:65)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

  • @krabbyPatty824
    @krabbyPatty824 2 ปีที่แล้ว

    14:39 just for myself

  • @danielfrost3967
    @danielfrost3967 2 ปีที่แล้ว

    Do you have a Discord server?

    • @tutorialsEU
      @tutorialsEU  2 ปีที่แล้ว

      Yes, we do! discord.com/invite/zwbrpCNB2M

  • @illsaveus
    @illsaveus ปีที่แล้ว

    How secure is this?