-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from pkorchak/add-google-sign-in
feat: sign in/out with Google
- Loading branch information
Showing
14 changed files
with
201 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ speed-measure-plugin*.json | |
|
||
# IDEs and editors | ||
/.idea | ||
/.vscode | ||
.project | ||
.classpath | ||
.c9/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import { Component } from '@angular/core'; | ||
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; | ||
import { AuthComponent } from '@widgets/auth/auth.component'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.less'] | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.less'] | ||
}) | ||
export class AppComponent { | ||
isCollapsed = false; | ||
export class AppComponent implements OnInit { | ||
isCollapsed = false; | ||
isSignedIn = false; | ||
isSigningIn = false; | ||
|
||
@ViewChild(AuthComponent) signIn: AuthComponent; | ||
|
||
constructor(private cdr: ChangeDetectorRef) { } | ||
|
||
ngOnInit(): void { | ||
this.isSignedIn = !!localStorage.getItem('token'); | ||
} | ||
|
||
onSignedIn(): void { | ||
this.isSignedIn = true; | ||
this.isSigningIn = false; | ||
} | ||
|
||
signOut(): void { | ||
this.isSignedIn = false; | ||
this.isSigningIn = true; | ||
this.cdr.detectChanges(); | ||
this.signIn.signOut(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,5 @@ | |
@dark-grey: #545454; | ||
@black: #000; | ||
@blue: #1890ff; | ||
@green: #00cc66; | ||
@blueviolet: blueviolet; | ||
@red: red; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="container"> | ||
<h2 class="header">Sign In</h2> | ||
<asl-google-signin-button type="standard" | ||
size="large" | ||
shape="pill" | ||
width="300" | ||
text="Sign In with Google"> | ||
</asl-google-signin-button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@import '~app/styles/global/_colors.less'; | ||
|
||
:host { | ||
position: absolute; | ||
display: flex; | ||
align-items: center; | ||
z-index: 100; | ||
width: 100%; | ||
height: 100%; | ||
background-color: @white; | ||
} | ||
|
||
.container { | ||
margin: 0 auto; | ||
height: fit-content; | ||
width: 360px; | ||
padding: 30px; | ||
border-radius: 6px; | ||
border: 1px solid #e8e8e8; | ||
box-shadow: 0 3px 3px 3px rgba(0, 0, 0, 0.05); | ||
} | ||
|
||
.header { | ||
margin-bottom: 20px; | ||
border-bottom: 1px solid #e8e8e8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; | ||
import { SocialAuthService, SocialUser } from '@abacritt/angularx-social-login'; | ||
|
||
@Component({ | ||
selector: 'app-auth', | ||
templateUrl: './auth.component.html', | ||
styleUrls: ['./auth.component.less'] | ||
}) | ||
export class AuthComponent implements OnInit { | ||
|
||
@Output() signedIn = new EventEmitter(); | ||
|
||
constructor(private socialAuthService: SocialAuthService) { } | ||
|
||
ngOnInit() { | ||
// TODO Add login by email | ||
/*this.loginForm = this.formBuilder.group({ | ||
email: ['', Validators.required], | ||
password: ['', Validators.required], | ||
});*/ | ||
this.socialAuthService.authState.subscribe((user: SocialUser) => { | ||
if (user && user.idToken != localStorage.getItem('token')) { | ||
localStorage.setItem('token', user.idToken); | ||
this.signedIn.emit(); | ||
} | ||
}); | ||
} | ||
|
||
signOut(): void { | ||
this.socialAuthService.signOut(); | ||
localStorage.removeItem('token'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NzButtonModule } from 'ng-zorro-antd/button'; | ||
import { AuthComponent } from './auth.component'; | ||
import { GoogleLoginProvider, SocialAuthServiceConfig, SocialLoginModule, GoogleSigninButtonModule } from '@abacritt/angularx-social-login'; | ||
import { environment } from './../../../environments/environment'; | ||
|
||
const ANT_DESIGN_MODULES = [NzButtonModule]; | ||
|
||
@NgModule({ | ||
declarations: [AuthComponent], | ||
imports: [ | ||
CommonModule, | ||
SocialLoginModule, | ||
GoogleSigninButtonModule, | ||
ANT_DESIGN_MODULES | ||
], | ||
providers: [ | ||
{ | ||
provide: 'SocialAuthServiceConfig', | ||
useValue: { | ||
autoLogin: false, | ||
providers: [ | ||
{ | ||
id: GoogleLoginProvider.PROVIDER_ID, | ||
provider: new GoogleLoginProvider(environment.googleOAuthClientId), | ||
}, | ||
], | ||
} as SocialAuthServiceConfig | ||
} | ||
], | ||
exports: [AuthComponent] | ||
}) | ||
export class AuthModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const environment = { | ||
production: true | ||
production: true, | ||
googleOAuthClientId: '666364708928-laj5k75go7q5dm985tjficnr78kggv4a.apps.googleusercontent.com' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters