Skip to content

Commit

Permalink
chore: bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
rustygreen committed Mar 14, 2024
1 parent 6b37f5e commit 427ed17
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 118 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0-rc.12 (2024-03-14)

This was a version bump only, there were no code changes.
7 changes: 7 additions & 0 deletions apps/demo/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const appConfig: ApplicationConfig = {
logging: {
logLevel: LogLevel.Debug,
},
// Uncomment below to require first and last name during sign up
// register: {
// metadata: [
// { field: 'first_name', label: 'First Name', required: true },
// { field: 'last_name', label: 'Last Name', required: true },
// ],
// },
}),
],
};
2 changes: 1 addition & 1 deletion libs/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ng-supabase/bootstrap",
"version": "1.0.0-rc.11",
"version": "1.0.0-rc.12",
"author": "Rusty Green <me@rusty.green>",
"contributors": [
"Rusty Green <me@rusty.green>"
Expand Down
2 changes: 1 addition & 1 deletion libs/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ng-supabase/core",
"version": "1.0.0-rc.11",
"version": "1.0.0-rc.12",
"author": "Rusty Green <me@rusty.green>",
"contributors": [
"Rusty Green <me@rusty.green>"
Expand Down
1 change: 0 additions & 1 deletion libs/core/src/lib/register/register.component.html
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
<p>register works!</p>
39 changes: 32 additions & 7 deletions libs/core/src/lib/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import {
Input,
signal,
OnInit,
Component,
ChangeDetectionStrategy,
} from '@angular/core';
Expand All @@ -26,8 +27,8 @@ import { SupabaseService } from '../supabase.service';
styleUrl: './register.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RegisterComponent {
@Input() title = 'Register Account';
export class RegisterComponent implements OnInit {
@Input() title = '';
@Input() email = '';

/**
Expand All @@ -52,28 +53,39 @@ export class RegisterComponent {
});

constructor(
readonly config: SupabaseConfig,
private readonly log: LogService,
private readonly config: SupabaseConfig,
private readonly supabase: SupabaseService,
private readonly routeService: RouteService
) {}

ngOnInit(): void {
this.title = this.title ?? this.config.register.title;

if (this.config.register.metadata.length) {
this.setupForMetadata();
}
}

async register(): Promise<void> {
if (this.form.invalid) {
return;
}

this.form.disable();
this.working.set(true);

try {
const email = this.form.value.email as string;
const data = this.form.value.metadata;
const emailRedirectTo = this.getRedirectTo();

this.form.disable();
this.working.set(true);

const { error } = await this.supabase.client.auth.signInWithOtp({
email,
options: {
shouldCreateUser: true,
emailRedirectTo,
data,
},
});

Expand All @@ -96,11 +108,24 @@ export class RegisterComponent {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
onError(error: AuthError): void {
onError(error: AuthError | string): void {
// Do nothing in here because this is just a hook for child
// components to easily subscribe to when an error occurs.
}

protected setupForMetadata(): void {
const group = new FormGroup({});

for (const meta of this.config.register.metadata) {
const validators = meta.required ? [Validators.required] : [];
const value = meta.defaultValue || '';
const control = new FormControl(value, validators);
group.addControl(meta.field, control);
}

this.form.addControl('metadata', group);
}

protected getRedirectTo(): string {
const fallback = this.config.routes.userProfile || this.config.routes.main;
return this.redirectToPath
Expand Down
37 changes: 1 addition & 36 deletions libs/core/src/lib/sign-in/sign-in.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ import {

// 3rd party.
import { Subject } from 'rxjs';
import { Provider } from '@supabase/supabase-js';

// Local.
import { WaitMessage } from '../wait-message';
import { RouteService } from '../route.service';
import { LogService } from '../logging/log.service';
import { SupabaseConfig } from '../supabase-config';
import { SupabaseService } from '../supabase.service';
import { SocialSignIn, SocialSignInItem } from './social-sign-in';
import { PersistentStorageService } from '../storage/persistent-storage.service';

@Component({
Expand All @@ -48,34 +46,20 @@ export class SignInComponent implements OnInit {
wait: WaitMessage | null = null;
signingIn = new Subject<boolean>();
errorMessage = new Subject<string>();
socialItems: SocialSignInItem[] = [];
form = new FormGroup({
email: new FormControl('', [Validators.required]),
password: new FormControl(''),
usePassword: new FormControl(false),
rememberMe: new FormControl(true),
});

get hasSocials(): boolean {
return this.socialItems.length > 0;
}

get hasNoSocials(): boolean {
return this.socialItems.length === 0;
}

protected readonly log = inject(LogService);
protected readonly config = inject(SupabaseConfig);
protected readonly supabase = inject(SupabaseService);
protected readonly routeService = inject(RouteService);
protected readonly storage = inject(PersistentStorageService);
protected readonly changeDetector = inject(ChangeDetectorRef);

constructor() {
const { signIn } = inject(SupabaseConfig);
this.socialItems = signIn.socialSignInItems;
}

ngOnInit(): void {
this.title = this.title ?? this.config.signIn.title;
const rememberMe = this.rememberMe ?? this.config.signIn.rememberMe;
Expand Down Expand Up @@ -115,25 +99,6 @@ export class SignInComponent implements OnInit {
: this.signInWithMagicLink();
}

async signInWithSocial(social: SocialSignIn): Promise<void> {
const result = this.config.signIn.onSocialSignIn?.(social);
if (result === false) {
return;
}

const { error } = await this.supabase.client.auth.signInWithOAuth({
provider: social as Provider,
});

if (error) {
this.log.debug(
`Unable to sign in with social '${social}'. ${error.message}`
);
this.errorMessage.next(error.message);
return;
}
}

protected revalidateAllControls(): void {
Object.values(this.form.controls).forEach((control) =>
control.updateValueAndValidity()
Expand Down Expand Up @@ -206,7 +171,7 @@ export class SignInComponent implements OnInit {
this.changeDetector.markForCheck();
this.trySaveRememberMe();
} catch (error) {
//todo
// TODO: Handle - @russell.green
} finally {
this.signingIn.next(false);
}
Expand Down
36 changes: 32 additions & 4 deletions libs/core/src/lib/supabase-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const DEFAULT_ROUTES: ComponentRoutes = {
main: '/',
signIn: '/sign-in',
register: '/register',
registerOrSignIn: '/auth',
setPassword: '/set-password',
resetPassword: '/reset-password',
};
Expand All @@ -27,6 +28,7 @@ export interface SupabaseConfigProperties {
mainRoute?: string;
signIn?: SignInConfigProperties;
logging?: LogConfig;
register?: RegisterProperties;
setPassword?: SetPasswordProperties;
routes?: Partial<ComponentRoutes>;
}
Expand All @@ -35,11 +37,25 @@ interface ComponentRoutes {
main: string;
signIn: string;
register: string;
registerOrSignIn: string;
setPassword: string;
resetPassword: string;
userProfile?: string;
}

interface UserRegistrationMetadata {
label: string;
field: string;
type?: 'text' | 'number';
required?: boolean;
defaultValue?: string | number;
}

interface RegisterProperties {
title?: string;
metadata?: UserRegistrationMetadata[];
}

type SocialSignInFn = (social: SocialSignIn) => boolean | void;

interface SignInConfigProperties {
Expand Down Expand Up @@ -75,7 +91,17 @@ class SetPasswordConfig implements SetPasswordProperties {
}
}

export class SupabaseSignInConfig implements SignInConfigProperties {
class RegisterConfig implements RegisterConfig {
title = '';
metadata: UserRegistrationMetadata[] = [];

constructor(init?: Partial<RegisterProperties>) {
Object.assign(this, init);
this.metadata = this.metadata || [];
}
}

export class SignInConfig implements SignInConfigProperties {
title = '';
magicLinks = true;
socials: SocialSignIn[] = [];
Expand All @@ -86,7 +112,7 @@ export class SupabaseSignInConfig implements SignInConfigProperties {
rememberMeStorageKey = 'supabase.auth.info';
onSocialSignIn?: SocialSignInFn;

constructor(init?: Partial<SupabaseSignInConfig>) {
constructor(init?: Partial<SignInConfig>) {
Object.assign(this, init);
this.setSocialSignInItems();
}
Expand All @@ -105,19 +131,21 @@ export class SupabaseSignInConfig implements SignInConfigProperties {
}

export class SupabaseConfig {
signIn: SupabaseSignInConfig;
signIn: SignInConfig;
api: BehaviorSubject<{ url: string; key: string }>;
logging?: LogConfig;
mainRoute = '/';
setPassword: SetPasswordConfig;
register: RegisterConfig;
routes: ComponentRoutes = DEFAULT_ROUTES;
redirectParamName: string | null | undefined = 'redirect';

constructor(init: SupabaseConfigProperties) {
Object.assign(this.routes, init.routes);
this.logging = init.logging;
this.setPassword = new SetPasswordConfig(init.setPassword);
this.signIn = new SupabaseSignInConfig(init.signIn);
this.signIn = new SignInConfig(init.signIn);
this.register = new RegisterConfig(init.register);
this.api = new BehaviorSubject<ApiInfo>({
url: init.apiUrl,
key: init.apiKey,
Expand Down
2 changes: 1 addition & 1 deletion libs/material/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ng-supabase/material",
"version": "1.0.0-rc.11",
"version": "1.0.0-rc.12",
"author": "Rusty Green <me@rusty.green>",
"contributors": [
"Rusty Green <me@rusty.green>"
Expand Down
2 changes: 1 addition & 1 deletion libs/primeng/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ng-supabase/primeng",
"version": "1.0.0-rc.11",
"version": "1.0.0-rc.12",
"author": "Rusty Green <me@rusty.green>",
"contributors": [
"Rusty Green <me@rusty.green>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
<p-selectButton
[options]="stateOptions"
[(ngModel)]="selection"
[(ngModel)]="type"
optionLabel="label"
optionValue="value"
></p-selectButton>

@if(selection === 'register'){
@if(type === 'register'){
<supabase-register></supabase-register>
} @else {
<supabase-sign-in></supabase-sign-in>
}

<!-- <p-tabView>
<p-tabPanel>
<ng-template pTemplate="header">
<i class="pi pi-user-plus mr-2"></i>
<span>Register</span>
</ng-template>
</p-tabPanel>
<p-tabPanel header="Sign In">
<ng-template pTemplate="header">
<i class="pi pi-sign-in mr-2"></i>
<span>Sign In</span>
</ng-template>
</p-tabPanel>
</p-tabView> -->
Loading

0 comments on commit 427ed17

Please sign in to comment.