feat: setup signup routes and redirect on success
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import { redirect } from "next/navigation"
|
import { redirect } from "next/navigation"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { signupVerify } from "@/constants/routes/signup"
|
||||||
import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
import { profileServiceServerActionProcedure } from "@/server/trpc"
|
import { profileServiceServerActionProcedure } from "@/server/trpc"
|
||||||
|
|
||||||
@@ -49,37 +50,39 @@ export const registerUser = profileServiceServerActionProcedure
|
|||||||
return { success: false, error: "Validation error" }
|
return { success: false, error: "Validation error" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let apiResponse
|
||||||
try {
|
try {
|
||||||
const apiResponse = await api.post(api.endpoints.v1.profile, {
|
apiResponse = await api.post(api.endpoints.v1.profile, {
|
||||||
body: parsedPayload.data,
|
body: parsedPayload.data,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
|
||||||
const text = await apiResponse.text()
|
|
||||||
console.error(
|
|
||||||
"registerUser api error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: input,
|
|
||||||
error: {
|
|
||||||
status: apiResponse.status,
|
|
||||||
statusText: apiResponse.statusText,
|
|
||||||
error: text,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return { success: false, error: "API error" }
|
|
||||||
}
|
|
||||||
|
|
||||||
const json = await apiResponse.json()
|
|
||||||
console.log("json", json)
|
|
||||||
|
|
||||||
// TODO: Redirect to actual success page.
|
|
||||||
redirect("/signup/success")
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Unexpected error", error)
|
console.error("Unexpected error", error)
|
||||||
return { success: false, error: "Unexpected error" }
|
return { success: false, error: "Unexpected error" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
|
console.error(
|
||||||
|
"registerUser api error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: input,
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
error: text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return { success: false, error: "API error" }
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await apiResponse.json()
|
||||||
|
console.log("registerUser: json", json)
|
||||||
|
|
||||||
|
// Note: The redirect needs to be called after the try/catch block.
|
||||||
|
// See: https://nextjs.org/docs/app/api-reference/functions/redirect
|
||||||
|
redirect(signupVerify[ctx.lang])
|
||||||
})
|
})
|
||||||
|
|||||||
21
constants/routes/signup.ts
Normal file
21
constants/routes/signup.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { LangRoute } from "@/types/routes"
|
||||||
|
|
||||||
|
export const signup: LangRoute = {
|
||||||
|
en: "/en/scandic-friends/join-scandic-friends",
|
||||||
|
sv: "/sv/scandic-friends/bli-medlem",
|
||||||
|
no: "/no/scandic-friends/registrer-deg-for-scandic-friends",
|
||||||
|
fi: "/fi/scandic-friends/liity-scandic-friends-ohjelmaan",
|
||||||
|
da: "/da/scandic-friends/tilmeld-dig-scandic-friends",
|
||||||
|
de: "/de/scandic-friends/werden-sie-mitglied-von-scandic-friends",
|
||||||
|
}
|
||||||
|
|
||||||
|
export const signupVerify: LangRoute = {
|
||||||
|
en: `${signup.en}/verify`,
|
||||||
|
sv: `${signup.sv}/verifiera`,
|
||||||
|
no: `${signup.no}/bekreft`,
|
||||||
|
fi: `${signup.fi}/vahvista`,
|
||||||
|
da: `${signup.da}/bekraeft`,
|
||||||
|
de: `${signup.de}/verifizieren`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// export const signup = [...Object.values(signupRoutes)]
|
||||||
Reference in New Issue
Block a user