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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ ALEXA_AMAZON_CLIENT_SECRET = secret

LARA_SECRET = secret
STAGE = dev
NODE_ENV = development

FRONTEND_CERTIFICATE_ARN = arn:aws:acm:eu-west-1:123456789012:certificate/12345678-1234-1234-1234-123456789012
BACKEND_CERTIFICATE_ARN = arn:aws:acm:eu-west-1:123456789012:certificate/12345678-1234-1234-1234-123456789012

HOSTED_ZONE_ID = Z0000000000000
FRONTEND_URL_WITHOUT_HTTPS = localhost:8080
BACKEND_URL_WITHOUT_HTTPS = localhost:3000/dev
BACKEND_URL_WITHOUT_HTTPS = localhost:3000/dev
1 change: 1 addition & 0 deletions .github/workflows/reusable-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
name: build-job
environment: ${{ inputs.environmentName }}
env:
NODE_ENV: ${{ inputs.environmentName }}
DEBUG: ${{ inputs.debug }}
MODE: ${{ inputs.mode }}
AUTH_HEADER: ${{ secrets.AUTH_HEADER }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-deploy-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
id-token: write
contents: read
env:
NODE_ENV: ${{ inputs.target }}
ALEXA_SKILL_STAGE: ${{ inputs.alexaSkillStage }}
DEBUG: ${{ inputs.debug }}
ALEXA_AMAZON_CLIENT_ID: ${{ secrets.ALEXA_AMAZON_CLIENT_ID }}
Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/resolvers/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GqlResolvers } from '@lara/api'

import { t } from '../i18n'
import { isDebug } from '../permissions'
import { saveUser, userByEmail, userById } from '../repositories/user.repo'
import { userById, userByEmail, saveUser } from '../repositories/user.repo'
import { createOAuthData } from '../services/oauth.service'
import { generateTrainee } from '../services/trainee.service'

Expand All @@ -24,6 +24,8 @@ const createMockUser = async (email: string) => {
return saveUser(userModel)
}

const isDevEnv = (): boolean => process.env.NODE_ENV === 'development'

export const authResolver: GqlResolvers = {
Mutation: {
login: async (_parent, { email }) => {
Expand All @@ -34,12 +36,12 @@ export const authResolver: GqlResolvers = {
let user = await userByEmail(email)

// creates mock user on dev stages
if (!user && isDebug()) {
if (!user && isDevEnv()) {
user = await createMockUser(email)
}

if (!user) {
return
throw new GraphQLError('USER_NOT_REGISTERED')
}

return createOAuthData(user)
Expand Down
11 changes: 10 additions & 1 deletion packages/frontend/src/components/ms-sign-in-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useLoginPageLoginMutation } from '../graphql'
import { useIsAuthenticated } from '@azure/msal-react'
import { EventMessage, EventType, PopupEvent } from '@azure/msal-browser'
import { useNavigate } from 'react-router'
import { useToastContext } from '../hooks/use-toast-context'
import strings from '../locales/localization'

export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
fullsize?: boolean
Expand All @@ -18,6 +20,7 @@ export const SignInButton: React.FunctionComponent<ButtonProps> = () => {
const [mutate] = useLoginPageLoginMutation()
const isAuthenticated = useIsAuthenticated()
const navigate = useNavigate()
const { addToast } = useToastContext()

const [popupWindow, setPopupWindow] = useState<Window | null>(null)

Expand Down Expand Up @@ -52,7 +55,13 @@ export const SignInButton: React.FunctionComponent<ButtonProps> = () => {
login(data.login)
})
.catch((err) => {
console.log(err)
console.error(err)
addToast({
icon: 'Error',
title: strings.login.userNotRegisteredError.title,
text: strings.login.userNotRegisteredError.description,
type: 'error',
})
})
}
} catch (error) {
Expand Down
7 changes: 7 additions & 0 deletions packages/frontend/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const germanTranslation: Translation = {
back: 'zurück',
on: 'an',
off: 'aus',
login: {
userNotRegisteredError: {
title: 'Fehler bei der Anmeldung',
description:
'Leider sind Sie noch nicht registriert. Bitte wenden Sie sich an den Administrator oder Ihren Ausbilder.',
},
},
modal: {
defaultClose: 'Schließen',
},
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const englishTranslation: Translation = {
back: 'back',
on: 'on',
off: 'off',
login: {
userNotRegisteredError: {
title: 'Login failed',
description: 'Unfortunately, you are not yet registered. Please contact the administrator or your trainer.',
},
},
modal: {
defaultClose: 'Close',
},
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/locales/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export default interface Translation {
back: string
on: string
off: string
login: {
userNotRegisteredError: {
title: string
description: string
}
}
modal: {
defaultClose: string
}
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/src/templates/secondary-template.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React, { ReactNode } from 'react'

import { Paragraph, StyledSecondaryTemplateWrapper } from '@lara/components'
import { Toasts } from '../components/toasts'

interface SecondaryTemplateProps {
children: ReactNode
}

const SecondaryTemplate: React.FunctionComponent<SecondaryTemplateProps> = ({ children }) => (
<StyledSecondaryTemplateWrapper>
{children}
<Paragraph center>Lara {TAG || `pre-release @ ${REVISION.substring(0, 7)}`}</Paragraph>
</StyledSecondaryTemplateWrapper>
<div>
<Toasts />
<StyledSecondaryTemplateWrapper>
{children}
<Paragraph center>Lara {TAG || `pre-release @ ${REVISION.substring(0, 7)}`}</Paragraph>
</StyledSecondaryTemplateWrapper>
</div>
)

export default SecondaryTemplate
5 changes: 4 additions & 1 deletion packages/frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require('path')
const dotenv = require('dotenv')

const {
NODE_ENV,
MICROSOFT_CLIENT_ID,
MICROSOFT_TENANT_ID,
DEBUG,
Expand All @@ -21,7 +22,7 @@ const {
const DEFAULT_ENVIRONMENT = 'development'
const DEFAULT_MODE = 'development'

/** @returns {{mode: string, authHeader: string, supportMail: string, debug: boolean, microsoftClientID: string, frontendUrl: string, name: (*|string), microsoftTenantID: string, backendUrl: string}}} */
/** @returns {{mode: string, authHeader: string, supportMail: string, debug: boolean, microsoftClientID: string, frontendUrl: string, name: (*|string), microsoftTenantID: string, backendUrl: string, nodeEnv: string}}} */
const getEnvironmentConfig = () => {
const name = ENVIRONMENT_NAME ?? DEFAULT_ENVIRONMENT

Expand All @@ -34,6 +35,7 @@ const getEnvironmentConfig = () => {
console.log(`Using environment variables from ${envVarsPath}`)
return {
name,
nodeEnv: parsed.NODE_ENV ?? DEFAULT_ENVIRONMENT,
mode: parsed.MODE,
microsoftClientID: parsed.MICROSOFT_CLIENT_ID,
microsoftTenantID: parsed.MICROSOFT_TENANT_ID,
Expand All @@ -55,6 +57,7 @@ const getEnvironmentConfig = () => {
console.log(`Using injected environment variables from process.env`)
return {
name,
nodeEnv: NODE_ENV ?? DEFAULT_ENVIRONMENT,
mode: MODE ?? '',
microsoftClientID: MICROSOFT_CLIENT_ID ?? '',
microsoftTenantID: MICROSOFT_TENANT_ID ?? '',
Expand Down