Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BACKEND
- @CrossOrigin(origins = "http://localhost:4200") //Connects to the frontend
- @RestController
- public class AccountResource {
- @Autowired //Autowired automaticaly assigns the variable.
- private AccountHardcodedService accountService;
- @Autowired
- private JwtInMemoryUserDetailsService userService;
- //Returns the account with the username and password
- //{username} and {password} is passed in using @PathVariable
- @GetMapping("/accounts/{username}/account/{password}")
- public Account getAccount(@PathVariable String username, @PathVariable String password) {
- //The accountservice just returns the account with the username, all backend services should be setup kinda like this.
- return accountService.getAccount(username);
- }
- }
- //FRONTEND
- attemptLogin(username, password) {
- //The Axios.get parameter must be the same as the backend @GetMapping.
- return axios.get(`${API_URL}/accounts/${username}/login/${password}`);
- }
- //To access this user you can do this in the frontend:
- //accountBalance is a variable in the Account class in the backend.
- //To access the firstName of the account class you would do:
- //response.data.firstName;
- AccountDataService.getAccount(username)
- .then(response =>(
- console.log(response.data.accountBalance.toString())
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement