Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions web/src/app/app/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ <h1 class="app-page__title">Sign in</h1>
</mat-card-header>
<mat-card-content>
<form class="auth-form" [formGroup]="signInForm" (ngSubmit)="signIn()">
<button matButton="outlined" type="button" [disabled]="isSubmitting()" (click)="signInWithGoogle()">
Continue with Google
</button>

<p class="auth-separator" aria-hidden="true">or</p>

<mat-form-field>
<mat-label>Email</mat-label>
<input matInput type="email" formControlName="email" autocomplete="email" />
Expand Down
7 changes: 7 additions & 0 deletions web/src/app/app/login/login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@
font-size: 0.875rem;
text-align: right;
}

.auth-separator {
margin: 0;
text-align: center;
color: var(--mat-sys-on-surface-variant);
font-size: 0.875rem;
}
23 changes: 23 additions & 0 deletions web/src/app/app/login/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MockAuthService {

waitUntilInitialized = async (): Promise<void> => {};
signInWithPassword = async (): Promise<string | null> => null;
signInWithGoogle = vi.fn().mockResolvedValue(null);
signOut = async (): Promise<string | null> => null;
}

Expand Down Expand Up @@ -58,4 +59,26 @@ describe('LoginPage', () => {

expect(router.navigateByUrl).toHaveBeenCalledWith('/clubs', { replaceUrl: true });
});

it('starts Google sign-in with the latest redirectTo value', async () => {
const fixture = TestBed.createComponent(LoginPage);
const page = fixture.componentInstance as any;
fixture.detectChanges();
redirectTo = '/clubs/123';

await page.signInWithGoogle();

expect(auth.signInWithGoogle).toHaveBeenCalledWith('/clubs/123');
});

it('shows a Google sign-in error', async () => {
const fixture = TestBed.createComponent(LoginPage);
const page = fixture.componentInstance as any;
auth.signInWithGoogle.mockResolvedValue('OAuth provider unavailable');
fixture.detectChanges();

await page.signInWithGoogle();

expect(page.authMessage()).toBe('OAuth provider unavailable');
});
});
11 changes: 11 additions & 0 deletions web/src/app/app/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ export class LoginPage {

this.isSubmitting.set(false);
}

protected async signInWithGoogle(): Promise<void> {
this.authMessage.set(null);
this.isSubmitting.set(true);

const errorMessage = await this.auth.signInWithGoogle(this.getRedirectTo());
if (errorMessage) {
this.authMessage.set(errorMessage);
this.isSubmitting.set(false);
}
}
}
14 changes: 14 additions & 0 deletions web/src/app/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ export class AuthService {
return error?.message ?? null;
}

async signInWithGoogle(redirectPath = '/'): Promise<string | null> {
if (!this.authClient) {
return 'Supabase is not configured.';
}

const { error } = await this.authClient.signInWithOAuth({
provider: 'google',
options: {
redirectTo: this.buildRedirectUrl(redirectPath),
},
});
return error?.message ?? null;
}

async signUp(email: string, password: string): Promise<string | null> {
if (!this.authClient) {
return 'Supabase is not configured.';
Expand Down
Loading