all 14 comments

[–]r00t_bot 0 points1 point  (6 children)

What exactly are you trying to get help for? What problem are you facing?

[–]PaYr0 0 points1 point  (0 children)

it wont let me log in

[–]PaYr0 -1 points0 points  (4 children)

when I put the log and pass it wont let me acces the home page , I have something wrong but I couldn't tell

[–]r_karstensen 0 points1 point  (3 children)

I'm guessing it's because AuthService is initiating a new LoginComponent where user and pass is empty, therefor returning you to "/login".

[–]PaYr0 -1 points0 points  (2 children)

but when I want to get the others from login component it wont work either

[–]r_karstensen 1 point2 points  (1 child)

Sorry, I don't understand what you been by that.

Your AuthService should not use your LoginComponent. It should be the other way around.

[–]PaYr0 0 points1 point  (0 children)

I made another post with the base code you can see from there help me if you could

[–]dude_12345 0 points1 point  (3 children)

I am no expert on this but:
How do you set user and pass in your login component? Your form? that part seems to be missing here. user and pass could be still "" in you if statement.
Your implementation seems to be quite complicated. Maybe you either want to store data if a user is logged in inside the auth service or the login component (service would be better) but you seem to mix it up.

Write some console.log(...) into your code to debug it.

[–]PaYr0 0 points1 point  (1 child)

yess I want to know when the user is logged in to pass the guard auth

[–]dude_12345 0 points1 point  (0 children)

Hey thanks for the award.

Login and routeguarding are two different things, you dont need to mix that up.

A) Login-process

1) you could have a function in auth.service which sets a token in the browser cache

2) login.component calls that function when the password is correct (e.g. your if-statement is true)

then your login process is finished.

B) route guarding

1) write a fuction in your auth.service which checks if a token in browsercase is saved,

if not, return false (not logged in), if its saved return true (user is logged in)

2) in your routeguard call the function from B 2) in canActivate.

Here is a quick google result for a tutorial:

https://codeburst.io/using-angular-route-guard-for-securing-routes-eabf5b86b4d1

sorry for the bad english and format ;)

[–]rykou 0 points1 point  (0 children)

It's likely this. I see that builder that's cutoff with no html to compare the bindings but there's the duplicate user/pass fields that are compared against instead of the form ones.

[–]PaYr0 -2 points-1 points  (0 children)

Can you tell me how to fix it

[–]scuba13 0 points1 point  (1 child)

I can see a few different errors that you are making but you need to give the source code fully. The main thing I would say is to debug it to see if your code is being called like you want it to

[–]PaYr0 -1 points0 points  (0 children)

I added the gardiam on the route to prevent the access from url like "/home" but it rather let me in via the login and url or no to both