Angular 15 Authentication (Registration + Login + Role based access) using JSON server REST API

Sdílet
Vložit
  • čas přidán 9. 09. 2024
  • #angular #angular15 #nihiratechiees
    This video provides the steps for implementing Angular 15 Authentication.
    It includes below topics
    1, Registration & Login using JSON-SERVER API
    2, Authentication with role based access
    3, Enable user access/ role assignment by admin user
    System requirement
    =================
    1, Install/Upgrade Node.js Latest version
    * Angular v15 supports node.js versions: 14.20.x, 16.13.x and 18.10.x
    * In v15, Angular no longer supports node.js versions 14.[15-19].x or 16.[10-12].x.
    2, Upgrade Angular CLI
    npm uninstall -g @angular/cli
    npm install -g @angular/cli
    Application Setup
    ===============
    1, Create application ng new Application name
    2, Install Material UI ng add @angular/material
    3, Install Toast Alert npm install ngx-toastr -save
    4, Run Json-server API json-server --watch db.json
    Reference Link
    =============
    1, Angular Upgrade guide
    update.angular...
    2, Node.js
    nodejs.org/en/
    GitHub Link for sourcecode
    =======================
    github.com/nih...
    Join this channel to get access to perks:
    / @nihiratechiees

Komentáře • 190

  • @inesriahi2144
    @inesriahi2144 Před rokem +2

    I wanted to express my gratitude for this excellent video you've provided. Thank you for sharing such valuable content.

  • @StorytimewithHumi
    @StorytimewithHumi Před rokem +2

    Thanks a lot for uploading using Json-server API 😄

  • @cassianopacheco5407
    @cassianopacheco5407 Před rokem +1

    Thanks, Mate! Amazing tutorial!

  • @antoniocpjunior
    @antoniocpjunior Před rokem +4

    Thanks so much Bro! It's just what i need to start my project !!

  • @anmasa
    @anmasa Před rokem +2

    Me ha parecido un tutorial muy bueno y muy completo, darte las gracias por tu tiempo, saludos desde España.

  • @saminserge2674
    @saminserge2674 Před 11 měsíci

    Many thanks for this tutorial, very helpfully !

  • @gayankavinda9757
    @gayankavinda9757 Před rokem

    Thanks bro . I followed your tutorial It helps me well

  • @user-ti7gt4kk7p
    @user-ti7gt4kk7p Před rokem

    thank you, you have helped me a lot, greetings from Bolivia...

  • @akadeadahot7067
    @akadeadahot7067 Před rokem

    informative tutorial thank you for shearing it

  • @dharmendraputtu9286
    @dharmendraputtu9286 Před rokem

    Thank you so much for your sharing knowledge it is helpful in my interview as well

  • @funcoding1797
    @funcoding1797 Před 4 měsíci

    excellent, thanks😊👏👏👏

  • @mbuachege7639
    @mbuachege7639 Před 11 měsíci

    Great content, Thank you👊

  • @user-rw5qn6cd1k
    @user-rw5qn6cd1k Před rokem

    A very useful tutorial

  • @biplabsharma5344
    @biplabsharma5344 Před 11 měsíci

    Amazing sir

  • @vittorioeselik8022
    @vittorioeselik8022 Před rokem

    Ottimo tutorial. Grazie

  • @arshathjm
    @arshathjm Před rokem

    Great tutorial. thanks

  • @anabolovic643
    @anabolovic643 Před rokem

    Great! Thank you!

  • @FullStackDevGreg
    @FullStackDevGreg Před 9 měsíci

    Great video to get start with Angular. I'm from React/Nextjs I'm thinking of learning angular as well. my overall impression is that the learning curve seems no too stip, Please can you advise me other tutorial on how to work with, dynamic routing, internationalisation routing, redux(observable) thank you in advance.

    • @NihiraTechiees
      @NihiraTechiees  Před 9 měsíci

      Follow below video you will get most of the topic in angular
      czcams.com/video/rZCQiMdQsxE/video.html
      NGRX (same as REDUX) playlist
      czcams.com/play/PLfyWdpsiUiPC7bHmDDDM6gGgfo3mgMCAC.html

  • @saiyathuabdulvahafj2176

    Its a wonderful video thanks for the effort. Only one request from my side is do the authentication and authorization using jwt.

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Jwt video already I have done. Can you check my angular authentication playlist

  • @leenuslee
    @leenuslee Před rokem

    Nice!

  • @josbexerra8115
    @josbexerra8115 Před rokem

    Muchas gracias Mister Nihira por compartir conocimiento....

  • @keshav2kumar
    @keshav2kumar Před rokem +1

    If possible please make a detail video on 'how to write test cases' like this video please......

  • @keshav2kumar
    @keshav2kumar Před rokem

    Very nice ❤❤❤

  • @VijayKumar-fq4ie
    @VijayKumar-fq4ie Před rokem

    Good Tutorial 👍🏻

  • @user-bp8fn4pe6o
    @user-bp8fn4pe6o Před 11 měsíci

    Thanks.

  • @weixiangng8279
    @weixiangng8279 Před 5 měsíci

    Thanks for this tutorial. Can you also implement Auth Guard for the login part?

  • @dattatreyakulkarni541
    @dattatreyakulkarni541 Před 7 měsíci

    Your video is so helpful and I have one que, join option is there right, why it is , is there any tutorial videos available?

    • @NihiraTechiees
      @NihiraTechiees  Před 7 měsíci

      Join option? Can you share the time stamp I used

  • @Jet-jet-xb8hy
    @Jet-jet-xb8hy Před rokem

    Good tutorial, but you forgot to add error catcher in the log in. What if the user didn't register and tried enter credentials that is not yet created or registered.
    thank you

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      I got your point, but when I was planning this video it's just basic crud video. then just changed into basic registration. Upcoming videos will consider all real time facts

  • @dheerajraja9811
    @dheerajraja9811 Před rokem

    Would be better if you can create a video for interceptor as well with complete authentication and authorization

  • @brogidey860
    @brogidey860 Před rokem

    Good tutorial bro.. It would be very helpful if you can make a tutorial on how to preview and confirm form data before submitting it to the server in angular. Thank you for this tutorial

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      Noted your suggestions, will include future video

  • @shreeyapatil2308
    @shreeyapatil2308 Před 7 měsíci

    In my code, when I use auth guard in that file, it shows 'canactivate' is deprecated.

  • @user-dp9kp8mh8p
    @user-dp9kp8mh8p Před 10 měsíci

    I tried to use Angular material in a diffrent project to pop up a dialog component but it did not pop up at the center it was showing beneath the entire content of the component that trigers the pop up dialog and i followed the same steps like you did in this tutorial

  • @avani1511
    @avani1511 Před rokem

    This tutorial was amazing! Helped me out a lot with my personal project. However there's just one thing I can't seen to get right .The username is being attached to the apiURL and i'm getting a 404 not found. How can I fix this? I would like for when the user logs in and submits the form for the url capture the ID as this is how my routes are set up. {path: 'cat/:id', component: CatUserProfilePageComponent},

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      Can you share what url you provided and your route values.
      Better share details to my email

  • @DINESHKUMARC-sp4lq
    @DINESHKUMARC-sp4lq Před rokem +2

    sir pls upload all type of videos in tamil tamil la English's videos irrugu but tamil la videos illa pls consider this one and pls upload tamil

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Don't have enough time bro, will consider your request soon

  • @michaelacevedo172
    @michaelacevedo172 Před rokem

    Hi tankyou it is really usefull, but i have a mistake, the inputs form are aligned one after the other, i dont know if you gave some class to this?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Actually I am not added class. I just did in the dynamic manner (based on Formcontrol data formated)

  • @sangamithrapc6141
    @sangamithrapc6141 Před 5 měsíci

    Sir "json-server --watch db.json" when i enter this command its shows not recognised. Should I install json first??

  • @siddhantthorat3269
    @siddhantthorat3269 Před rokem

    Authgaurd not. Working sir, class constructor authgaurd cannot be invoked without new

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      czcams.com/video/1FgSlvsywXg/video.html follow this video

  • @connectingdots0-0
    @connectingdots0-0 Před rokem

    Hi, What would be the role name to add Customer detail? I am getting error "you are not authorized to access."

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Follow the video hope you will get the information.

  • @sunnygupta4201
    @sunnygupta4201 Před 7 měsíci

    is there any video on duplicate email validation. like when yours is entering duplicate email then it will verify from db and give alter that this email is already exist

  • @premkishore7902
    @premkishore7902 Před 11 měsíci

    Thanks for the video. But not getting through authentication. while submitting the login form, getting "An error occurred during registration."

    • @NihiraTechiees
      @NihiraTechiees  Před 11 měsíci

      What error you received?

    • @premkishore7902
      @premkishore7902 Před 10 měsíci

      @@NihiraTechiees CanActivate is deprecate in latest version, so can you please update the solution, thanks in advance.

  • @Gyannea
    @Gyannea Před rokem

    Do you have any idea why the login screen does not respond correctly to reducing the size of the browser? When decreasing the horizontal width, the right side gets cut off. The left side does fine. I have tried all kinds of FlexBox directives (which seem to work) but I can't get the cards to shrink monotonically. The right side always gets cut off.

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Will check, design point of view I am also not familier

    • @Gyannea
      @Gyannea Před rokem

      @@NihiraTechiees Regardless, this a great video! I have learned a boatload.👍👍👍

  • @ranjithanaikp
    @ranjithanaikp Před rokem

    Hi, I have followed your tutorial. Till the updatepopupcompoentn its working fine, but while updating the isactive checkbox auto check is not working, and also unable to update also, its throwing 404 error on clicking update button could you please tell me where i may went wrong?

  • @davebudah
    @davebudah Před rokem

    First comment

  • @Gyannea
    @Gyannea Před rokem

    I do not understand regex at all, but I think you said at least 8 characters and at least one upper case, lower case, number, and special character. But if I start my password with a number the validator regex fails. If I don't start with a number, I can create a password that passes. What can I do to allow a password to start with a number?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Honestly I am also not good making regax. I just used pattern that i got from google search.
      In your case just browse you can generate regax through online based on the requirements. Else watch some regax basics video

  • @archanabarsagade2699
    @archanabarsagade2699 Před rokem +1

    canActivate is deprecated .. how to solve this?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      What is your angular version?

    • @archanabarsagade2699
      @archanabarsagade2699 Před rokem

      @@NihiraTechiees Angular CLI: 15.2.7
      Node: 18.16.0
      Package Manager: npm 9.5.1

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Sorry for the late reply from angular 15.2 canActivate deprecated so we have to use CanActivateFn follow the below code
      export const auto1Guard: CanActivateFn = (route, state) => {
      return true;
      };

  • @janoshollosi9570
    @janoshollosi9570 Před rokem

    Users can overwrite key values at session storage. How can can you protect against it?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      If security is the concern we can encrypt and store

  • @anchalpatel10
    @anchalpatel10 Před rokem

    At 30:17 when i am clicking on submit then neither it is submitting and nor it is navigating to login . I have all previous steps , they all the correct. How can i solve this?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Could you confirm whether register data stored in json file

    • @anchalpatel10
      @anchalpatel10 Před rokem

      @@NihiraTechiees no it is not storing in json

  • @jhonnidarshan3094
    @jhonnidarshan3094 Před rokem

    Hi bro , can you make video on authorization in lambada in aws gateway with angular integration

  • @durga.k.b.durga.kb.8941
    @durga.k.b.durga.kb.8941 Před 4 měsíci

    My error is not recognized for internal external command how to add

  • @rashmitakamble5843
    @rashmitakamble5843 Před rokem

    I am getting the error for the ' localhost:3000'. Err_connection_refused

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      May the the port number already in use so try with other port number ex. 8000

  • @MalikKamranKhalil
    @MalikKamranKhalil Před rokem

    Hi bro , can you make video on authorization in CASL with angular integration?

  • @chennaack996
    @chennaack996 Před rokem

    Bro, Why we are using FormBuilder instead of FormGroup and FormControl. Is there any advantages?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      Form builder is abstract of form group, control, array. Instead of creating new object of all items we can use form builder instance

  • @earvinemunene1744
    @earvinemunene1744 Před rokem

    am submitting the registration details its not storing them in the db
    why?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Can you debug, where it's lost the data. Also check if any issues

  • @karthick.b5071
    @karthick.b5071 Před rokem

    Hi bro, I tried your guidelines, but stuck in datasource in mattable is not working

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Chek material ui version in package.json and confirm have you imported mattablemodule

  • @av_0211
    @av_0211 Před rokem

    13:33 ---- Error: Can't resolve 'node_modules/ngz-toastr/toastr.css' in 'D:\angular\first'

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Did you installed toaster package

    • @av_0211
      @av_0211 Před rokem

      @@NihiraTechiees yes resolved

    • @av_0211
      @av_0211 Před rokem +1

      @@NihiraTechiees 31:33 my form is not submitting.
      sumbit button is not working and getting data in db.json as well.. can't see registered successful message

    • @shraddhachaudhari7842
      @shraddhachaudhari7842 Před 10 měsíci

      Same submit button isn't working

  • @mohiburrahman5639
    @mohiburrahman5639 Před rokem

    hello can you make a video for radio button and text area display in console without button .use only click radio button. like 1st radio button is yes and the same line text area. but only one click for both. thank you

  • @mr_umairkhan07
    @mr_umairkhan07 Před rokem

    SIR I WRITE SAME CODE BUT MY USER DOESNOT UPDATE it give error For url ?
    Why can you explain plzzz

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Put console.log and find where it's breaking

    • @mr_umairkhan07
      @mr_umairkhan07 Před rokem

      console Is working When A establish Role Then giving this error

  • @thotcher9706
    @thotcher9706 Před 9 měsíci

    how to change the login form, so i can login with the name, not the id?

    • @NihiraTechiees
      @NihiraTechiees  Před 9 měsíci +1

      Create model class before sending to api comvert form value into this model format

    • @thotcher9706
      @thotcher9706 Před 9 měsíci

      @@NihiraTechiees ok ty, what should i do when i want to insert the users data into a postgresql/any sql database when a registration is made?

  • @shraddhachaudhari7842
    @shraddhachaudhari7842 Před 10 měsíci

    Will it work using Angular16 actually data is not adding after clicking submit btn

    • @NihiraTechiees
      @NihiraTechiees  Před 10 měsíci

      It will work. Can check step by step you missing data?

  • @ichraknajar91
    @ichraknajar91 Před rokem

    hello sir i dont know why but i have a problem while executing this command ng c register (Error: This command is not available when running the Angular CLI outside a workspace.) just in this project but in other anglar project its working .please some help .

  • @ranjithanaikp
    @ranjithanaikp Před rokem

    HI, I have folowed your tutorial, after creating complete registration, when clicked on submit, its going to else part, showing please enter valid data,
    please help me with this code.

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Can you share the data you passed and reactive form declaration

    • @ranjithanaikp
      @ranjithanaikp Před rokem

      @@NihiraTechiees
      export class RegisterComponent implements OnInit {
      constructor(private _formBuilder: FormBuilder, private _toastr: ToastrService,
      private _authService: AuthService, private router: Router) { }
      ngOnInit(): void {
      }
      registrationForm = this._formBuilder.group({
      id: this._formBuilder.control('', Validators.compose([Validators.required, Validators.minLength(5)])),
      name: this._formBuilder.control('', Validators.required),
      password: this._formBuilder.control('', Validators.compose([Validators.required, Validators.pattern('(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.
      ])(?=.*[A-Z])(?=.*[a-z]).*$"')])),
      email: this._formBuilder.control('', Validators.compose([Validators.required, Validators.email])),
      gender: this._formBuilder.control('male'),
      role: this._formBuilder.control(''),
      isActive: this._formBuilder.control(false),
      })
      proceedRegistraion(){
      if(this.registrationForm.valid){
      this._authService.proceedRegister(this.registrationForm.value).subscribe(data=>{
      console.log("success")
      this._toastr.success('Please contact admin for enable access','registered successfully');
      this.router.navigate(['login'])
      })
      }
      else{
      console.log("failure")
      this._toastr.warning("Please enter valid data")
      }
      }
      }
      form:

      username



      Name



      Password



      Email




      Male
      Female



      Submit
      Back to Login

    • @ranjithanaikp
      @ranjithanaikp Před rokem

      @@NihiraTechiees I think problem is with the password field. after entering proper password the field still looks red color.

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      I hope we used pattern validation for password so time being remove pattern validation. I will verify pattern validation if any findings share with you.
      If possible try to join the membership

    • @ranjithanaikp
      @ranjithanaikp Před rokem

      @@NihiraTechiees yes its working, i removed password validation, but why the problem with validation?

  • @christopher.r0104
    @christopher.r0104 Před rokem

    how to i add menu in json array in this project

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      You can keep in array. Based on the data we can generate menu dynamically

  • @serignecheikhahmettidianes7085

    Very good work.
    Can I have your Backend code of angular application.

  • @noraitafti74
    @noraitafti74 Před 7 měsíci

    toast notifications are not working for me :(

    • @NihiraTechiees
      @NihiraTechiees  Před 7 měsíci

      Have you followed all steps?

    • @noraitafti74
      @noraitafti74 Před 7 měsíci

      @@NihiraTechiees I had to add some lines in app.config and now is working

  • @durga.k.b.durga.kb.8941
    @durga.k.b.durga.kb.8941 Před 4 měsíci

    How to add the jaon server in vs code

  • @new_contents_all_day
    @new_contents_all_day Před rokem

    if you add user password in json server , any one can view the data in jason server , so is this safe ?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +2

      Json server is kind of fake api (only used for study or development). Real-time you have to use separate api

    • @new_contents_all_day
      @new_contents_all_day Před rokem

      @@NihiraTechiees oh okay, so I have to use something like MySQL and all

    • @superuser8636
      @superuser8636 Před rokem

      You need to hash the password

    • @new_contents_all_day
      @new_contents_all_day Před rokem

      @@superuser8636 bro, yeah I thought about it, we need a whole server running in another port and angular running in separate port , the whole db logic must run in server .. but this is very cumbersome

    • @superuser8636
      @superuser8636 Před rokem +1

      @@new_contents_all_day Welcome to full-stack programming where that's standard practice.. You can use the bcrypt library for hashing your passwords

  • @mohiburrahman5639
    @mohiburrahman5639 Před rokem

    can i contact with you by phone for some problem about Angular!! please

  • @ananthualpd
    @ananthualpd Před rokem

    sessionStorage geting null vale? pls help sir

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      Did you set the value in session

    • @ananthualpd
      @ananthualpd Před rokem

      @@NihiraTechiees
      Thanks for your reply sir,
      I am new to angular, I just follow your steps. How to set the value in session?

    • @NihiraTechiees
      @NihiraTechiees  Před rokem +1

      Ok can you share the files to my mail. I will check and let you know by tmrw

    • @ananthualpd
      @ananthualpd Před rokem

      @@NihiraTechiees
      Sorry sir, I re-watched full video, i missed the portion where the setItem.
      Thanks for your valuable time..

  • @vaibhavlande7829
    @vaibhavlande7829 Před rokem

    where i can get BE api source code

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      This video I used json- server api(fake api) it's just json file

  • @shudhakarkumargupta7236

    first which password use

  • @mr_umairkhan07
    @mr_umairkhan07 Před rokem

    PUT /user/[object℅20Object] 404

  • @Shubhamindory
    @Shubhamindory Před rokem

    please give me source code sir

  • @hugosilva-kg6vr
    @hugosilva-kg6vr Před rokem

    Show

  • @atozupdates-telugu3120
    @atozupdates-telugu3120 Před 10 měsíci

    sir, can't install ngx-toastr it does not install it shows an error, icant understand . what can i do please clarify my doubt
    here is my issue :
    D:\sai-angular-practice\veeru_workspace>npm install ngx-toastr -save
    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE unable to resolve dependency tree
    npm ERR!
    npm ERR! While resolving: veeru-workspace@0.0.0
    npm ERR! Found: @angular/common@15.2.10
    npm ERR! node_modules/@angular/common
    npm ERR! @angular/common@"^15.2.0" from the root project
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! peer @angular/common@">=16.0.0-0" from ngx-toastr@17.0.2
    npm ERR! node_modules/ngx-toastr
    npm ERR! ngx-toastr@"*" from the root project
    npm ERR!
    npm ERR! Fix the upstream dependency conflict, or retry
    npm ERR! this command with --force or --legacy-peer-deps
    npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
    npm ERR!
    npm ERR!
    npm ERR! For a full report see:
    npm ERR! C:\Users\91961\AppData\Local
    pm-cache\_logs\2023-10-18T16_54_38_869Z-eresolve-report.txt
    npm ERR! A complete log of this run can be found in:
    npm ERR! C:\Users\91961\AppData\Local
    pm-cache\_logs\2023-10-18T16_54_38_869Z-debug-0.log
    idont understand my problem , please solve this

    • @NihiraTechiees
      @NihiraTechiees  Před 10 měsíci

      While install use the specific version.... Look like version conflict

  • @mathipamakgato
    @mathipamakgato Před rokem

    Firstly thank you very much for the great tutorial, I seem to have an issue on the below code while trying to login, "this.userdata" is undefined but I do have the data from the db.json file futhermore when debugging I can see the username value going to the service. Please help!!
    if (this.loginform.valid) {
    this.service.Getbycode(this.loginform.value.username).subscribe(res => {
    this.userdata = res;
    console.log(this.userdata);

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Can you confirm your API returning data? If yes what value you getting console.log(this.userdata).

  • @harshavardhanpatekar5697
    @harshavardhanpatekar5697 Před 6 měsíci

    Json server not starting. Please help!!

  • @user-jn8ht9ww4q
    @user-jn8ht9ww4q Před rokem

    I follow your code but user registration form (submit) is not taking any value. Why it is so Answer please

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      Is your screen refreshed after you submit?

    • @eshitashimu3906
      @eshitashimu3906 Před rokem

      @@NihiraTechiees yes brother. Now it works

    • @user-jn8ht9ww4q
      @user-jn8ht9ww4q Před rokem

      If I do not run in json server in the browser at that time input value (registration/ login) is not submitting. why it is so?? If I run json server in the browser at that time it works fine. please let me know the actual issue for this.

    • @NihiraTechiees
      @NihiraTechiees  Před rokem

      It's dummy api also need to be running mode. Just running -- watch command is fine not required to open url in browser

    • @user-jn8ht9ww4q
      @user-jn8ht9ww4q Před rokem

      @@NihiraTechiees One more queries: Toastr is not working properly. it just only shows the messages in left bottom position but not any block box with color. Currently I am using angular cli 15.2.3 and ngx-toastr 16.1.0 Additionally I followed all the set up for displaying toastr but its not working properly. Please let me know why it is so?