Skip to content

Commit

Permalink
🎨 yarn fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Format Fairy authored and JLarky committed May 18, 2023
1 parent 970ff96 commit f2f4e4c
Show file tree
Hide file tree
Showing 41 changed files with 154 additions and 89 deletions.
10 changes: 7 additions & 3 deletions src/components/AuthSync.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useActiveOrg, useAuthInfo } from './propelauth';
import { useMemo, useEffect } from 'react';
import { trpc } from './trpc';
import cookie from 'js-cookie';
import { useEffect, useMemo } from 'react';

import { AUTH_COOKIE_NAME } from '../constants';
import { parseJwt } from './jwt';
import { useActiveOrg, useAuthInfo } from './propelauth';
import { trpc } from './trpc';

export function AuthSync() {
// refresh_token is stored in secure cookie, so the only way to get access_token is to wait for propel auth to get new access_token from their backend
Expand All @@ -19,6 +20,7 @@ export function AuthSync() {
orgId,
};
}

return { isLoggedIn: undefined, accessToken: undefined, userId: undefined };
}, [auth, orgId]);

Expand All @@ -28,6 +30,7 @@ export function AuthSync() {
authMutation.mutate(params);
return;
}

if (params.isLoggedIn) {
// store new cookie to backend if new access_token is much fresher than the one in backend or userId doesn't match
const cookieValues = new URLSearchParams(cookie.get(AUTH_COOKIE_NAME) || '');
Expand All @@ -40,6 +43,7 @@ export function AuthSync() {
authMutation.mutate(params);
return;
}

const expFromCookie = cookieValues.get('exp');
const expFromCookieNumber = Number(expFromCookie) || 0;
console.log('expFromCookieNumber', jwtValues.exp - expFromCookieNumber);
Expand Down
1 change: 1 addition & 0 deletions src/components/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRef } from 'react';

import { trpc, TRPCProvider } from './trpc';

export function Counter(props: React.ComponentProps<typeof CounterInteral>) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AuthProvider, LoginManager } from './propelauth';

import { env } from '../config';
import { AuthProvider, LoginManager } from './propelauth';
import { PropelAuthCSS } from './PropelAuthCSS';

export function Login() {
Expand All @@ -15,6 +14,7 @@ export function LoginInternal() {
const redirectToYourProduct = () => {
window.location.href = '/app';
};

return (
<PropelAuthCSS>
<LoginManager
Expand Down
3 changes: 1 addition & 2 deletions src/components/LoginPasswordless.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AuthProvider, LoginPasswordless } from './propelauth';

import { env } from '../config';
import { AuthProvider, LoginPasswordless } from './propelauth';
import { PropelAuthCSS } from './PropelAuthCSS';

export function Login() {
Expand Down
5 changes: 3 additions & 2 deletions src/components/PropelAuthCSS.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createPortal } from 'react-dom';
import { BaseElements } from '@propelauth/base-elements';
import { useCallback, useRef, useState } from 'react';
import { createPortal } from 'react-dom';

import { BetaComponentLibraryProvider } from './propelauth';
import { BaseElements } from '@propelauth/base-elements';

export function PropelAuthCSS({ children }: { children: React.ReactNode }) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Signup.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AuthProvider, Signup as SignupManager } from './propelauth';

import { env } from '../config';
import { AuthProvider, Signup as SignupManager } from './propelauth';
import { PropelAuthCSS } from './PropelAuthCSS';

export function Signup() {
const redirectToYourProduct = () => {
window.location.href = '/app';
};

return (
<AuthProvider authUrl={env.PUBLIC_AUTH_URL}>
<PropelAuthCSS>
Expand Down
21 changes: 13 additions & 8 deletions src/components/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import type { OrgMemberInfo } from '@propelauth/javascript';
import type { UseAuthInfoLoggedInProps } from '@propelauth/react/types/useAuthInfo';

import { env } from '../../config';
import { AuthSync } from '../AuthSync';
import { SupportWidget } from '../fogbender/Support';
import { LoginInternal } from '../Login';
import {
AuthProvider,
saveOrgSelectionToLocalStorage,
useActiveOrg,
useAuthInfo,
saveOrgSelectionToLocalStorage,
useRedirectFunctions,
} from '../propelauth';
import type { OrgMemberInfo } from '@propelauth/javascript';
import type { UseAuthInfoLoggedInProps } from '@propelauth/react/types/useAuthInfo';
import { env } from '../../config';
import { TRPCProvider } from '../trpc';
import { AuthSync } from '../AuthSync';
import { SupportWidget } from '../fogbender/Support';
import { LoginInternal } from '../Login';
import { AppNav } from './Nav';
import { Layout } from './Layout';
import { AppNav } from './Nav';

export function App() {
return (
Expand All @@ -35,6 +36,7 @@ function AppInteral() {
if (auth.loading === true) {
return <div className="container my-10 mx-4">Loading...</div>;
}

if (auth.user === null) {
return (
<>
Expand All @@ -45,6 +47,7 @@ function AppInteral() {
</>
);
}

if (!activeOrg) {
const orgs = auth.orgHelper.getOrgs();
if (orgs.length === 0) {
Expand All @@ -64,6 +67,7 @@ function AppInteral() {
</>
);
}

return (
<>
<h1 className="text-2xl font-bold text-center">Please select an organization</h1>
Expand All @@ -88,6 +92,7 @@ function AppInteral() {
</>
);
}

return <AppWithOrg auth={auth} activeOrg={activeOrg} />;
}

Expand Down
10 changes: 7 additions & 3 deletions src/components/app/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import classNames from 'clsx';
import { useState, useEffect, useRef } from 'react';
import { useEffect, useRef, useState } from 'react';

import { env } from '../../config';
import { SupportWidget } from '../fogbender/Support';
import {
requireActiveOrg,
saveOrgSelectionToLocalStorage,
useLogoutFunction,
useRedirectFunctions,
} from '../propelauth';
import { env } from '../../config';
import { SupportWidget } from '../fogbender/Support';

export function AppNav() {
const menuRef = useRef<HTMLDivElement>(null);
Expand All @@ -33,15 +34,18 @@ export function AppNav() {
setIsMenuOpen(false);
}
};

const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
setIsMenuOpen(false);
}
};

if (isMenuOpen) {
document.addEventListener('click', closeMenu);
document.addEventListener('keydown', handleEscape);
}

return () => {
document.removeEventListener('click', closeMenu);
document.removeEventListener('keydown', handleEscape);
Expand Down
12 changes: 7 additions & 5 deletions src/components/app/Prompts.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DehydratedState, useQueryClient } from '@tanstack/react-query';
import { getQueryKey } from '@trpc/react-query';
import { useReducer, useRef } from 'react';

import { env } from '../../config';
import { AuthProvider, requireActiveOrg } from '../propelauth';
import { TRPCProvider, trpc } from '../trpc';
import { AuthSync } from '../AuthSync';
import { useReducer, useRef } from 'react';
import { AppNav } from './Nav';
import { AuthProvider, requireActiveOrg } from '../propelauth';
import { trpc, TRPCProvider } from '../trpc';
import { Layout } from './Layout';
import { AppNav } from './Nav';

export function Prompts(props: { dehydratedState: DehydratedState }) {
return (
Expand Down Expand Up @@ -40,7 +41,7 @@ function Interal() {
},
});
const runPromptMutation = trpc.prompts.runPrompt.useMutation();
const [showAddPrompt, toggleShowAddPrompt] = useReducer((state) => !state, !!!!!!!!!false);
const [showAddPrompt, toggleShowAddPrompt] = useReducer((state) => !state, !false);
const { activeOrg } = requireActiveOrg();
const orgId = activeOrg?.orgId || '';
const promptsQuery = trpc.prompts.getPrompts.useQuery(
Expand Down Expand Up @@ -97,6 +98,7 @@ function Interal() {
return;
}
}

addPromptMutation.mutate(
{ orgId, prompt, response },
{
Expand Down
7 changes: 4 additions & 3 deletions src/components/app/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useQueryClient } from '@tanstack/react-query';
import { getQueryKey } from '@trpc/react-query';
import { useReducer } from 'react';

import { env } from '../../config';
import { AuthProvider, requireActiveOrg } from '../propelauth';
import { TRPCProvider, trpc } from '../trpc';
import { AuthSync } from '../AuthSync';
import { useReducer } from 'react';
import { AuthProvider, requireActiveOrg } from '../propelauth';
import { trpc, TRPCProvider } from '../trpc';
import { Layout } from './Layout';
import { AppNav } from './Nav';

Expand Down
28 changes: 16 additions & 12 deletions src/components/fogbender/Support.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import type { OrgMemberInfo } from '@propelauth/react';
import type { UseAuthInfoLoggedInProps } from '@propelauth/react/types/useAuthInfo';
import {
FogbenderWidget,
FogbenderSimpleFloatie,
FogbenderProvider,
FogbenderConfig,
FogbenderIsConfigured,
FogbenderHeadlessWidget,
FogbenderIsConfigured,
FogbenderProvider,
FogbenderSimpleFloatie,
FogbenderUnreadBadge,
FogbenderWidget,
} from 'fogbender-react';
import { AuthProvider } from '../propelauth';
import { TRPCProvider } from '../trpc';
import { AuthSync } from '../AuthSync';
import { useMemo } from 'react';
import type { OrgMemberInfo } from '@propelauth/react';
import type { UseAuthInfoLoggedInProps } from '@propelauth/react/types/useAuthInfo';
import { apiServer, queryKeys, useQuery } from '../client';
import type { FogbenderTokenResponse } from '../../types/types';

import { env } from '../../config';
import { useActiveOrg, useAuthInfo } from '../propelauth';
import type { FogbenderTokenResponse } from '../../types/types';
import { AppNav } from '../app/Nav';
import { AuthSync } from '../AuthSync';
import { apiServer, queryKeys, useQuery } from '../client';
import { AuthProvider } from '../propelauth';
import { useActiveOrg, useAuthInfo } from '../propelauth';
import { TRPCProvider } from '../trpc';

export const FullPageSupport = () => {
return (
Expand All @@ -42,6 +43,7 @@ export const SupportWidget = ({ kind }: { kind: 'widget' | 'floatie' | 'badge' }
if (kind !== 'widget') {
return null;
}

return (
<div className="container mt-8 mx-auto">
<h3 className="text-2xl font-bold">Prompts with Friends / Support</h3>
Expand Down Expand Up @@ -69,6 +71,7 @@ export const SupportWidget = ({ kind }: { kind: 'widget' | 'floatie' | 'badge' }
/>
);
}

return null;
};

Expand Down Expand Up @@ -106,6 +109,7 @@ export const Internal = ({
if (!userJWT) {
return;
}

return {
widgetId,
customerId: activeOrg.orgId,
Expand Down
1 change: 1 addition & 0 deletions src/components/head/posthog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import posthog from 'posthog-js';

import { env } from '../../config';

if (env.PUBLIC_POSTHOG_KEY) {
Expand Down
8 changes: 5 additions & 3 deletions src/components/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export function parseJwt(token: string) {
var base64Url = token.split('.')[1];
const base64Url = token.split('.')[1];
if (!base64Url) {
return;
}
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(

const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const jsonPayload = decodeURIComponent(
window
.atob(base64)
.split('')
Expand All @@ -18,6 +19,7 @@ export function parseJwt(token: string) {
if (typeof parsed === 'object' && parsed !== null) {
return parsed as Record<string, unknown>;
}

console.error('Could not parse JWT payload', parsed);
return;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/landing/B2B.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import Layout from '../../layouts/Layout.astro';
import b2b7logo from '../../assets/b2b7.svg';
import wink from '../../assets/wink.svg';
import Layout from '../../layouts/Layout.astro';
const websiteTitle = 'B2B SaaS Kit';
Expand Down
2 changes: 1 addition & 1 deletion src/components/landing/Dev.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Layout from '../../layouts/Layout.astro';
import { websiteTitle } from '../../constants';
import Layout from '../../layouts/Layout.astro';
export const prerender = true;
---

Expand Down
4 changes: 2 additions & 2 deletions src/components/landing/Prod.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import Layout from '../../layouts/Layout.astro';
import { websiteTitle } from '../../constants';
import b2b7logo from '../../assets/b2b7.svg';
import free from '../../assets/free.svg';
import { websiteTitle } from '../../constants';
import Layout from '../../layouts/Layout.astro';
export const prerender = true;
---

Expand Down
12 changes: 6 additions & 6 deletions src/components/propelauth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export function requireActiveOrg() {

export {
AuthProvider,
useActiveOrg,
useAuthInfo,
saveOrgSelectionToLocalStorage,
useRedirectFunctions,
BetaComponentLibraryProvider,
Signup,
LoginManager,
LoginPasswordless,
saveOrgSelectionToLocalStorage,
Signup,
useActiveOrg,
useAuthInfo,
useLogoutFunction,
LoginManager,
useRedirectFunctions,
};
Loading

0 comments on commit f2f4e4c

Please sign in to comment.