API redirect to back-end from nuxt

This commit is contained in:
Julien Nahum 2024-01-14 19:28:39 +01:00
parent 1cfd6ef163
commit cc12a2dd1d
3 changed files with 15 additions and 6 deletions

View File

@ -28,10 +28,10 @@ class AppSumoAuthController extends Controller
// otherwise start login flow by passing the encrypted license key id // otherwise start login flow by passing the encrypted license key id
if (is_null($license->user_id)) { if (is_null($license->user_id)) {
return redirect(url('/register?appsumo_license='.encrypt($license->id))); return redirect(front_url('/register?appsumo_license='.encrypt($license->id)));
} }
return redirect(url('/register?appsumo_error=1')); return redirect(front_url('/register?appsumo_error=1'));
} }
private function retrieveAccessToken(string $requestCode): string private function retrieveAccessToken(string $requestCode): string
@ -82,11 +82,11 @@ class AppSumoAuthController extends Controller
if (is_null($license->user_id)) { if (is_null($license->user_id)) {
$license->user_id = Auth::id(); $license->user_id = Auth::id();
$license->save(); $license->save();
return redirect(url('/home?appsumo_connect=1')); return redirect(front_url('/home?appsumo_connect=1'));
} }
// Licensed already attached // Licensed already attached
return redirect(url('/home?appsumo_error=1')); return redirect(front_url('/home?appsumo_error=1'));
} }
/** /**

View File

@ -224,7 +224,6 @@ export default {
if (responseData.form && responseData.form.cleanings && Object.keys(responseData.form.cleanings).length > 0) { if (responseData.form && responseData.form.cleanings && Object.keys(responseData.form.cleanings).length > 0) {
alert.warning(responseData.message) alert.warning(responseData.message)
} else if (responseData.message) { } else if (responseData.message) {
console.log(responseData.message)
alert.success(responseData.message) alert.success(responseData.message)
} }
}, },
@ -256,7 +255,6 @@ export default {
this.amplitude.logEvent('form_saved', { form_id: this.form.id, form_slug: this.form.slug }) this.amplitude.logEvent('form_saved', { form_id: this.form.id, form_slug: this.form.slug })
this.displayFormModificationAlert(data) this.displayFormModificationAlert(data)
}).catch((error) => { }).catch((error) => {
console.log(error)
if (error.response.status === 422) { if (error.response.status === 422) {
this.validationErrorResponse = error.response.data this.validationErrorResponse = error.response.data
this.showValidationErrors() this.showValidationErrors()

View File

@ -0,0 +1,11 @@
export default defineNuxtRouteMiddleware((to, from) => {
if (process.client) return
const config = useRuntimeConfig()
if (to.fullPath.startsWith('/api')) {
const path = to.fullPath.replace('/api', '')
return navigateTo(config.public.apiBase + path, { redirectCode: 301, external: true })
}
})