Skip to content

Commit

Permalink
Merge pull request #106 from Shaoe/featAuth
Browse files Browse the repository at this point in the history
Authentication
  • Loading branch information
jozef-slezak authored Nov 26, 2022
2 parents a4a12e6 + ae75c3a commit f575ada
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 41 deletions.
10 changes: 9 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
VITE_HASURA_GRAPHQL_ENDPOINT = "https://test.hasura.magicsk.eu/v1/graphql"
VITE_HASURA_GRAPHQL_SECRET = "c2akHldMLELW7z5RFUMu8AnUxyHAXAThFzW5JZK7HejgMjG5cn7kr1m0C0Vefdbc"
VITE_INJECT_MODE = "devServer"
VITE_INJECT_MODE = "jamstack"

#VITE_AUTH_MODE = "admin_secret" # "token" | "admin_secret"

VITE_AUTH_PROVIDER = "firebase"

VITE_FIREBASE_API_KEY = "AIzaSyBQrfw2BoTJL7SEFwP7fnNih6FNxegw7QY"
VITE_FIREBASE_DOMAIN = "dev-iteria.firebaseapp.com"
VITE_FIREBASE_PERSISTANCE="LOCAL_DB" # NONE | LOCAL_BROWSER | LOCAL_DB | SESSION
11 changes: 10 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
VITE_HASURA_GRAPHQL_ENDPOINT = "https://test.hasura.magicsk.eu/v1/graphql"
VITE_HASURA_GRAPHQL_SECRET = "c2akHldMLELW7z5RFUMu8AnUxyHAXAThFzW5JZK7HejgMjG5cn7kr1m0C0Vefdbc"
VITE_INJECT_MODE = "jamstack"
VITE_INJECT_MODE = "jamstack"

#VITE_AUTH_MODE = "admin_secret" # "token" | "admin_secret"


VITE_AUTH_PROVIDER = "firebase"

VITE_FIREBASE_API_KEY = "AIzaSyBQrfw2BoTJL7SEFwP7fnNih6FNxegw7QY"
VITE_FIREBASE_DOMAIN = "dev-iteria.firebaseapp.com"
VITE_FIREBASE_PERSISTANCE="LOCAL_DB" # NONE | LOCAL_BROWSER | LOCAL_DB | SESSION
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
"typescript": "4.5.4",
"vite": "2.8.6"
}
}
}
38 changes: 28 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified public/Sources.tar.gz
Binary file not shown.
36 changes: 24 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
I18nProvider,
useLocale,
DataContext,
GraphqlcodegenDataProvider
GraphqlcodegenDataProvider,
authExchange,
useClient
} from '@iteria-app/component-templates'
import '../src/mixins/chartjs'
import { theme } from './theme'
Expand All @@ -16,28 +18,38 @@ import * as graphqlgen from './generated/graphql'
import introspection from './generated/introspect.json'
import {
cacheExchange,
ClientOptions,
createClient,
debugExchange,
fetchExchange,
Provider as UrqlProvider,
Provider as UrqlProvider
} from 'urql'

const graphqlcodegenDataProvider = new GraphqlcodegenDataProvider(
graphqlgen,
introspection.__schema as any
)

const client = createClient({
url: import.meta.env.VITE_HASURA_GRAPHQL_ENDPOINT as string,
exchanges: [debugExchange, fetchExchange],
fetchOptions: {
headers: {
'x-hasura-admin-secret': import.meta.env.VITE_HASURA_GRAPHQL_SECRET as string
const App = () => {
const clientOptions: ClientOptions = {
url: import.meta.env.VITE_HASURA_GRAPHQL_ENDPOINT as string,
exchanges: [debugExchange, authExchange(), fetchExchange]
//requestPolicy: 'cache-and-network',
}
const superClient = createClient({
...clientOptions,
fetchOptions: {
headers: {
'x-hasura-admin-secret': import.meta.env
.VITE_HASURA_GRAPHQL_SECRET as string
}
}
},
})
})

let client = createClient(clientOptions)

if (import.meta.env.VITE_AUTH_MODE === 'admin_secret') client = superClient

const App = () => {
const routing = useRoutes(routes)
const locale = useLocale()
const messagesObject = messages(locale)
Expand All @@ -55,7 +67,7 @@ const App = () => {

App.propTypes = {
locale: PropTypes.string,
messages: PropTypes.object,
messages: PropTypes.object
}

export default App
12 changes: 6 additions & 6 deletions src/layouts/DashboardLayout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ interface AppBarProps extends MuiAppBarProps {
}

const AppBar = styled(MuiAppBar, {
shouldForwardProp: (prop) => prop !== 'open',
shouldForwardProp: (prop) => prop !== 'open'
})<AppBarProps>(({ theme, open }) => ({
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
duration: theme.transitions.duration.leavingScreen
}),
...(open && {
width: `calc(100% - ${drawerWidth}px)`,
marginLeft: `${drawerWidth}px`,
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
}),
}),
duration: theme.transitions.duration.enteringScreen
})
})
}))

const TopBar = ({
Expand Down Expand Up @@ -69,7 +69,7 @@ const TopBar = ({

TopBar.propTypes = {
className: PropTypes.string,
onMobileNavOpen: PropTypes.func,
onMobileNavOpen: PropTypes.func
}

export default TopBar
27 changes: 26 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,39 @@ import {
LocaleContextProvider,
ErrorBoundary,
ThemeContextProvider,
AuthContextProvider,
initializeProvider
} from '@iteria-app/component-templates'

const provider = import.meta.env.VITE_AUTH_PROVIDER as string
const firebaseAuthDomain = import.meta.env.VITE_FIREBASE_DOMAIN as string
const firebaseApiKey = import.meta.env.VITE_FIREBASE_API_KEY as string
const persistance = import.meta.env.VITE_FIREBASE_PERSISTANCE as string
const config = {
provider: provider,
domain: firebaseAuthDomain,
apiKey: firebaseApiKey,
persistance: persistance
//domain: auth0Domain,
//clientId: aut0ClientID,
//audience: auth0Audience,
//domain: keycloakDomain,
//realm: keycloakRealm,
//clientId: keycloakClientID,
//clientSecret: keycloakClientSecret,
//adminSecret: keycloakAdminSecret,
}

const authProvider = initializeProvider(config)

ReactDOM.render(
<ErrorBoundary>
<Router>
<LocaleContextProvider>
<ThemeContextProvider>
<App />
<AuthContextProvider auth={authProvider}>
<App />
</AuthContextProvider>
</ThemeContextProvider>
</LocaleContextProvider>
</Router>
Expand Down
22 changes: 13 additions & 9 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import NotFoundView from '../src/views/errors/NotFoundView'
import RegisterView from '../src/views/auth/RegisterView'

import {
ErrorBoundary,
generatePagesRoutes,
DefaultLoginView,
ResetPassword,
SignupWithEmail,
ErrorBoundary
} from '@iteria-app/component-templates'
import * as generatedGraphql from './generated/graphql'
import HomePage from './pages/home'
Expand Down Expand Up @@ -35,7 +38,7 @@ const newRoutes = Object.keys(filebasedRouting).map((route) => {
<ErrorBoundary>
<Container />
</ErrorBoundary>
),
)
}
})

Expand All @@ -47,24 +50,25 @@ const routes = [
{
path: 'app',
element: <DashboardLayout />,
children: routing,
children: routing
},
{
path: 'test',
element: <DashboardLayout />,
children: newRoutes,
children: newRoutes
},
{
path: '/',
element: <DashboardLayout />,
children: [
{ path: 'login', element: <LoginView /> },
{ path: 'register', element: <RegisterView /> },
{ path: 'login', element: <DefaultLoginView /> },
{ path: 'resetpassword', element: <ResetPassword /> },
{ path: 'signup', element: <SignupWithEmail /> },
{ path: '404', element: <NotFoundView /> },
{ path: '/', element: <Navigate to="/app/home" /> },
{ path: '*', element: <NotFoundView /> },
],
},
{ path: '*', element: <NotFoundView /> }
]
}
]

export default routes

0 comments on commit f575ada

Please sign in to comment.