전체 코드
const CLIENT_ID =
'~~~~~~~~~~~~~~~~~~~~~~~~~~~9s.apps.googleusercontent.com';
const AUTHORIZE_URI = 'https://accounts.google.com/o/oauth2/v2/auth';
@Component({
selector: 'app-nav',
templateUrl: './nav.component.html',
styleUrls: ['./nav.component.css'],
})
export class NavComponent implements OnInit {
loggedin: boolean = false;
queryStr;
loginUrl;
initQueryStr() {
this.queryStr = stringify({
response_type: 'token',
client_id: CLIENT_ID,
redirect_uri: window.location.href,
scope: 'https://www.googleapis.com/auth/contacts.readonly',
});
this.loginUrl = AUTHORIZE_URI + '?' + this.queryStr;
}
initLoggedin() {
if (window.sessionStorage.getItem('access_token')) {
this.loggedin = true;
} else {
this.loggedin = false;
}
}
constructor(
private location: Location,
private router: Router,
private authService: AuthService
) {}
goForward() {
this.location.forward();
}
postWrite() {
this.router.navigateByUrl('/postWrite');
}
logOut() {
window.sessionStorage.removeItem('access_token');
this.loggedin = false;
window.location.hash = '';
window.location.reload;
this.initQueryStr();
}
ngOnInit(): void {
this.initQueryStr();
this.initLoggedin();
const { access_token } = parse(window.location.hash.substr(1));
if (window.location.hash.substr(1).length > 5) {
window.sessionStorage.setItem(
'access_token',
window.location.hash.substr(1)
);
this.loggedin = true;
window.location.hash = '';
}
}
}
'Angular.js' 카테고리의 다른 글
Angular http 통신 등의 결과를 subscribe로 받아올때 에러가 return된다면? (0) | 2020.08.04 |
---|---|
OAuth2 로그인 scope 여러개 지정하기 복수 (1) | 2020.07.31 |
구글 OAuth2 로그인 "확인되지 않은 앱 입니다. " 해결방법 !! [angular https ssl통신 설정방법 ] (0) | 2020.07.30 |
Toast UI Viewer 탑재하는법! (0) | 2020.07.24 |
html 을 string 으로 appendChild 해주는 방법! (0) | 2020.07.24 |