Skip to content

Commit

Permalink
chore: setup home page (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
conradbekondo authored Dec 27, 2024
1 parent 65fe807 commit 92de08e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 16 deletions.
19 changes: 11 additions & 8 deletions netlify/functions/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const db = drizzle({
passport.use(new GoogleStrategy({
clientID: String(process.env['OAUTH2_CLIENT_ID']),
clientSecret: String(process.env['OAUTH2_CLIENT_SECRET']),
callbackURL: `${process.env['BASE_URL']}/api/auth/google/callback`,
callbackURL: `${process.env['URL']}/api/auth/google/callback`,
}, async (accessToken: string, __: string, profile: Profile, done: VerifyCallback) => {
let existingUser = await db.query.users.findFirst({
where: eq(users.users.credentials, profile.id)
Expand Down Expand Up @@ -73,13 +73,16 @@ passport.deserializeUser<number>((id, done) => {
});

const router = Router();
router.get('/', passport.authenticate('google', {
session: false,
scope: [
'profile',
'email',
]
}));
router.get('/', (req,res,next) => {
console.debug(process.env['URL']);
passport.authenticate('google', {
session: false,
scope: [
'profile',
'email',
]
})(req,res,next);
});
router.get('/callback', passport.authenticate('google', {
failureRedirect: '/auth/login', session: false,
}), (req: Request, res: Response) => {
Expand Down
9 changes: 8 additions & 1 deletion src/app/pages/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<p>home works!</p>
<div class="p-1">
<p-menubar [model]="menuItems">

Check notice on line 2 in src/app/pages/home/home.component.html

View workflow job for this annotation

GitHub Actions / Qodana for JS

Undefined binding

Property model is not provided by any applicable directives nor by <p-menubar> element
<ng-template #end>
<p-menu #userMenu [popup]="true" [model]="userMenuItems"/>

Check notice on line 4 in src/app/pages/home/home.component.html

View workflow job for this annotation

GitHub Actions / Qodana for JS

Undefined binding

Property model is not provided by any applicable directives nor by <p-menu> element

Check notice on line 4 in src/app/pages/home/home.component.html

View workflow job for this annotation

GitHub Actions / Qodana for JS

Undefined binding

Property popup is not provided by any applicable directives nor by <p-menu> element
<p-avatar class="cursor-pointer" (click)="userMenu.toggle($event)" [image]="principal()?.avatar" shape="circle"/>

Check notice on line 5 in src/app/pages/home/home.component.html

View workflow job for this annotation

GitHub Actions / Qodana for JS

Undefined binding

Property image is not provided by any applicable directives nor by <p-avatar> element

Check failure on line 5 in src/app/pages/home/home.component.html

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unresolved TypeScript reference

Unresolved function or method toggle()
</ng-template>
</p-menubar>
</div>
3 changes: 3 additions & 0 deletions src/app/pages/home/home.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
@apply grid grid-rows-[auto_1fr] w-full h-full;
}
25 changes: 23 additions & 2 deletions src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { Component } from '@angular/core';
import { Menubar } from 'primeng/menubar';
import { MenuItem } from 'primeng/api';
import { dispatch, select } from '@ngxs/store';
import { principal, SignOut } from '../../state/user';
import { Avatar } from 'primeng/avatar';
import { Menu } from 'primeng/menu';

@Component({
selector: 'tm-home',
imports: [],
imports: [

Check failure on line 11 in src/app/pages/home/home.component.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Invalid usage of imports in non-standalone components

Only standalone components can use imports
Menubar,
Avatar,
Menu
],
templateUrl: './home.component.html',
styleUrl: './home.component.scss'
})
export class HomeComponent {

Check failure on line 19 in src/app/pages/home/home.component.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Missing or invalid component, directive or pipe declaration in a module

HomeComponent is not declared in any Angular module

private readonly signOut = dispatch(SignOut);
readonly principal = select(principal);
readonly menuItems: MenuItem[] = [
{ label: 'Home', routerLink: '/', icon: 'pi pi-home', routerLinkActiveOptions: { match: true } },
];
readonly userMenuItems: MenuItem[] = [
{ label: 'Profile', icon: 'pi pi-user', routerLink: '/auth/profile' },
{ separator: true },
{
label: 'Sign out', icon: 'pi pi-sign-out', command: () => this.signOut()
},
]
}
8 changes: 7 additions & 1 deletion src/app/state/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ export class GoogleSignInFlow {

export class FinishGoogleSignInFlow {
static type = `${prefix} finish google sign-in flow`
constructor(readonly accessToken: string){}

constructor(readonly accessToken: string) {
}
}

export class SignOut {
static type = `${prefix} sign out`
}
24 changes: 20 additions & 4 deletions src/app/state/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Action, createSelector, provideStates, State, StateContext, StateToken } from '@ngxs/store';
import {
Action,
createPropertySelectors,
createSelector,
provideStates,
State,
StateContext,
StateToken
} from '@ngxs/store';
import { EnvironmentProviders, Injectable } from '@angular/core';
import { FinishGoogleSignInFlow, GoogleSignInFlow } from './actions';
import { FinishGoogleSignInFlow, GoogleSignInFlow, SignOut } from './actions';
import { jwtDecode } from 'jwt-decode';
import { throwError } from 'rxjs';
import { patch } from '@ngxs/store/operators';
import { Navigate } from '@ngxs/router-plugin';


export * from './actions';

export type Principal = {
Expand Down Expand Up @@ -34,6 +40,13 @@ type Context = StateContext<UserStateModel>;
@Injectable()
class UserState {

@Action(SignOut)
signOut(ctx: Context) {
ctx.setState(defaultState);
ctx.dispatch(new Navigate(['/']));
location.reload();
}

@Action(GoogleSignInFlow)
googleSignInFlow(ctx: Context, { redirect, apiBase }: GoogleSignInFlow) {
localStorage.setItem('auth-redirect', redirect);
Expand Down Expand Up @@ -64,4 +77,7 @@ export function provideUserState(...providers: EnvironmentProviders[]) {
return provideStates([UserState], ...providers);
}

const slices = createPropertySelectors(USER);

export const isUserSignedIn = createSelector([USER], state => state.signedIn);
export const principal = slices.principal;
1 change: 1 addition & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "primeicons/primeicons.css";
@layer tailwind-base, primeng, tailwind-utilities;

@layer tailwind-base {
Expand Down

0 comments on commit 92de08e

Please sign in to comment.