Giter Site home page Giter Site logo

amplify-user-profile's People

Contributors

mjzone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

amplify-user-profile's Issues

Username is not getting printed after logging in.

Once the user is successfully logged in to the profile, username is not getting printed. Once the profile page is mannually refreshed, it gets printed on the page. I tried to log the username on console, it works fine and the username gets printed once the profile page is loaded at the sign in. I even tried printing a static variable in profile page. It also does not get printed while the profile page is being loaded after signing in. But it also gets printed on the page, once the profile page is mannually reloaded / refreshed.

auth.component.ts

import { Component, OnInit } from '@angular/core';

import { Hub, Auth } from 'aws-amplify';
import { Router } from '@angular/router';

@Component({
  selector: 'app-auth',
  templateUrl: './auth.component.html',
  styleUrls: ['./auth.component.scss']
})
export class AuthComponent implements OnInit {

  constructor(public router: Router) {
   }

  ngOnInit(): void {
    Hub.listen('auth', (data) => {
      console.log(data);
      switch (data.payload.event) {
          case 'signIn':
              this.router.navigate(['/profile']);
              break;
          case 'signOut':
            this.router.navigate(['/login']);
            break;  
      }
  });
  }

}

profile.component.ts

import { Component, OnInit } from '@angular/core';
import { Auth, Hub } from 'aws-amplify';
import { Router } from '@angular/router';

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.scss']
})
export class ProfileComponent implements OnInit {

  userId: string;
  userName: string;
  var1  : String = "temp";


  constructor(public router: Router) { }

  ngOnInit(): void { 
    Auth.currentAuthenticatedUser({
      bypassCache: false
    }).then(async user => {
      this.userId = user.attributes.sub;
      this.userName = user.username;
      console.log(this.userName);
      
    })
    .catch(err => console.log("err assigning"));
   }

  logOut() {
    console.log("Log out");
    this.router.navigate(['/login']);
  }

}

profile.component.html

Hello {{userName}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.