Skip to content

Commit

Permalink
Add translations for the user authentication endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Apr 14, 2024
1 parent 0c0d106 commit f69279b
Show file tree
Hide file tree
Showing 9 changed files with 928 additions and 821 deletions.
4 changes: 2 additions & 2 deletions composer.lock

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

33 changes: 26 additions & 7 deletions frontend/composables/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,26 @@ export default async function useAuth() {
}

try {
const response = await $fetch('/api/auth/login', {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, password }),
body: JSON.stringify({
langcode: locale.value,
email,
password,
}),
})

if ('error' in response) {
return {
data: null,
error: new Error(response.error?.statusCode?.toString() ?? '500'),
if (!response || Math.floor(response.status / 100) !== 2) {
const json = await response.json()

if (json.message) {
return {
data: null,
error: json.message,
}
}
}

Expand Down Expand Up @@ -90,7 +98,7 @@ export default async function useAuth() {
}

try {
const response = await $fetch('/api/auth/register', {
const response = await fetch('/api/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -103,6 +111,17 @@ export default async function useAuth() {
}),
})

if (!response || Math.floor(response.status / 100) !== 2) {
const json = await response.json()

if (json.message) {
return {
data: null,
error: json.message,
}
}
}

return {
data: response,
error: null,
Expand Down
1 change: 0 additions & 1 deletion frontend/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ logout: Log out
email: Email
password: Password
password_confirm: Confirm password
login_error_credentials: Incorrect email or password
login_error_generic: An error occurred while logging in. Please try again later.
login_register_link: No account yet? Register here.
register_login_link: Already have an account? Log in here.
Expand Down
1 change: 0 additions & 1 deletion frontend/i18n/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ logout: Uitloggen
email: E-mail
password: Wachtwoord
password_confirm: Bevestig wachtwoord
login_error_credentials: Onjuist e-mailadres of wachtwoord
login_error_generic: Er is een fout opgetreden tijdens het inloggen. Probeer het later opnieuw.
login_register_link: Nog geen account? Registreer hier.
register_login_link: Al een account? Log hier in.
Expand Down
15 changes: 4 additions & 11 deletions frontend/pages/user/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ async function login(e: SubmitEvent) {
return navigateTo(localePath('/user'))
}
catch (error: any) {
console.error(error)
if (process.client) {
switch (error?.message) {
case '403':
toast.error(t('login_error_credentials'))
break
default:
toast.error(t('login_error_generic'))
break
}
if (typeof error === 'string')
toast.error(error)
else
toast.error(t('login_error_generic'))
}
}
finally {
Expand Down
18 changes: 16 additions & 2 deletions frontend/pages/user/register/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const email = ref('')
const password = ref('')
const password_confirm = ref('')
const toast = useToast()
async function register(e: SubmitEvent) {
e.preventDefault()
isLoading.value = true
Expand All @@ -25,8 +27,20 @@ async function register(e: SubmitEvent) {
return navigateTo(localePath('/user/register/confirm'))
}
catch (error) {
console.error(error)
catch (error: any) {
if (process.client) {
if (typeof error === 'string') {
toast.error(error)
return
}
if (typeof error === 'object') {
for (const key in error) {
if (error[key])
toast.error(error[key])
}
}
}
}
finally {
isLoading.value = false
Expand Down
Loading

0 comments on commit f69279b

Please sign in to comment.