Skip to content

Commit dfa7ead

Browse files
committed
Mmmmm nioce
1 parent b301413 commit dfa7ead

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+852
-102
lines changed

Diff for: apps/web/src/app/portal/(authenticated)/dashboard/[teamId]/settings/(account)/_common/ui/password/password-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function changeOrCreatePasswordAction(
3434

3535
try {
3636
const userServiceClient = getUserServiceClient()
37-
userServiceClient.setPassword({
37+
await userServiceClient.setPassword({
3838
$typeName: 'zitadel.user.v2.SetPasswordRequest',
3939
userId: session.user.id,
4040
verification: {

Diff for: apps/web/src/app/portal/(authenticated)/dashboard/[teamId]/settings/billing/_common/ui/team-plan/team-change-plan-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function TeamChangePlanDialog({
109109
const canSelect = !isSelected && canAfford && !isPending
110110

111111
return (
112-
<PlanCard key={plan.id} plan={plan}>
112+
<PlanCard key={plan.id} plan={plan} className="min-w-[320px]">
113113
<div className="flex flex-col w-full">
114114
<CheckerCustom
115115
disableWhen={!canAfford && !isSelected}

Diff for: apps/web/src/app/portal/(authenticated)/dashboard/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function GET(request: NextRequest) {
1111
)
1212
} catch {
1313
return NextResponse.redirect(
14-
`${request.nextUrl.protocol}//${request.nextUrl.host}/portal/login`,
14+
`${request.nextUrl.protocol}//${request.nextUrl.host}/portal`,
1515
)
1616
}
1717
}

Diff for: apps/web/src/app/portal/(authenticated)/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function Layout({
77
const authSession = await getSessionData()
88

99
if (!authSession.isLoggedIn) {
10-
redirect('/portal/login')
10+
redirect('/portal')
1111
}
1212

1313
return children

Diff for: apps/web/src/app/portal/(authenticated)/verify/_common/ui/verify-form/resend-code/resend-code-action.ts renamed to apps/web/src/app/portal/(hero)/(authenticated)/verify/_common/ui/verify-form/resend-code/resend-code-action.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { headers } from 'next/headers'
44
import { getSessionData } from 'src/app/portal/_common/lib/client-config'
5+
import { getBaseUrl } from 'src/app/portal/_common/lib/get-base-url'
56
import { getAdminStyroClient } from 'src/app/portal/_common/lib/styro/styro-client'
67
import { getUserServiceClient } from 'src/app/portal/_common/lib/zitadel-client'
78

@@ -11,10 +12,6 @@ export async function resendCodeAction() {
1112
return { error: 'Not logged in' }
1213
}
1314

14-
const headers_ = await headers()
15-
const host = headers_.get('Host')!
16-
const proto = headers_.get('X-Forwarded-Proto') || 'https'
17-
1815
try {
1916
const userServiceClient = getUserServiceClient()
2017
const response = await userServiceClient.resendEmailCode({
@@ -38,7 +35,7 @@ export async function resendCodeAction() {
3835
email: {
3936
type: 'verify_email',
4037
frontend: {
41-
baseUrl: `${proto}://${host}`,
38+
baseUrl: await getBaseUrl(),
4239
},
4340
verification: {
4441
code: response.verificationCode,

Diff for: apps/web/src/app/portal/(authenticated)/verify/layout.tsx renamed to apps/web/src/app/portal/(hero)/(authenticated)/verify/layout.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Container } from '@sushiswap/ui'
22
import { redirect } from 'next/navigation'
33
import { getSession } from 'src/app/portal/_common/lib/client-config'
4-
import { getUserServiceClient } from '../../_common/lib/zitadel-client'
4+
import { getUserServiceClient } from '../../../_common/lib/zitadel-client'
55

66
export default async function Layout({
77
children,
@@ -30,9 +30,5 @@ export default async function Layout({
3030
redirect('/portal/verify/api/set-email-verified')
3131
}
3232

33-
return (
34-
<Container maxWidth="md" className="pt-16">
35-
{children}
36-
</Container>
37-
)
33+
return <Container maxWidth="md">{children}</Container>
3834
}

Diff for: apps/web/src/app/portal/(unauthenticated)/login/_common/ui/login-action.ts renamed to apps/web/src/app/portal/(hero)/(index)/@login/_common/ui/login-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { redirect } from 'next/navigation'
55
import { createSession } from 'src/app/portal/_common/lib/client-config'
66
import { getUserServiceClient } from 'src/app/portal/_common/lib/zitadel-client'
77
import { isPromiseRejected } from 'sushi'
8-
import { createZitadelSession } from '../../../_common/lib/create-zitadel-session'
8+
import { createZitadelSession } from '../../../../(unauthenticated)/_common/lib/create-zitadel-session'
99
import { loginFormSchema } from './login-form-schema'
1010

1111
export type FormState =

Diff for: apps/web/src/app/portal/(unauthenticated)/login/_common/ui/login-form-schema.ts renamed to apps/web/src/app/portal/(hero)/(index)/@login/_common/ui/login-form-schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod'
2-
import { zPassword } from '../../../../_common/lib/zod'
2+
import { zPassword } from '../../../../../_common/lib/zod'
33

44
export const loginFormSchema = z.object({
55
email: z.string().email(),
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Container } from '@sushiswap/ui'
22

33
export default function Layout({ children }: { children: React.ReactNode }) {
4-
return (
5-
<Container maxWidth="md" className="pt-16">
6-
{children}
7-
</Container>
8-
)
4+
return <Container maxWidth="md">{children}</Container>
95
}

Diff for: apps/web/src/app/portal/(unauthenticated)/login/page.tsx renamed to apps/web/src/app/portal/(hero)/(index)/@login/page.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Separator } from '@sushiswap/ui'
22
import Link from 'next/link'
3-
import { OAuthButton } from '../../_common/ui/oauth/oauth-button'
4-
import { OAuthProvider } from '../../_common/ui/oauth/oauth-config'
3+
import { OAuthButton } from '../../../_common/ui/oauth/oauth-button'
4+
import { OAuthProvider } from '../../../_common/ui/oauth/oauth-config'
55
import { LoginForm } from './_common/ui/login-form'
66

77
export default function Page() {
88
return (
9-
<div className="flex flex-col space-y-12">
10-
<h1 className="text-4xl font-bold">Sign In</h1>
9+
<div className="flex flex-col space-y-8">
10+
<h1 className="text-3xl font-bold">Sign In</h1>
1111
<span className="flex flex-col space-y-8">
1212
<div className="flex w-full flex-col space-y-6">
1313
<LoginForm />
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function Page() {
2-
return <>A</>
2+
return <></>
33
}

Diff for: apps/web/src/app/portal/(hero)/(index)/layout.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getSessionData } from '../../_common/lib/client-config'
2+
3+
export default async function Layout({
4+
login,
5+
user,
6+
}: {
7+
login: React.ReactNode
8+
user: React.ReactNode
9+
}) {
10+
const session = await getSessionData()
11+
12+
if (session.isLoggedIn) {
13+
return user
14+
}
15+
16+
return login
17+
}

Diff for: apps/web/src/app/portal/(unauthenticated)/api/auth/callback/lib/login.ts renamed to apps/web/src/app/portal/(hero)/(unauthenticated)/api/auth/callback/lib/login.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createZitadelSession } from 'src/app/portal/(unauthenticated)/_common/lib/create-zitadel-session'
1+
import { createZitadelSession } from 'src/app/portal/(hero)/(unauthenticated)/_common/lib/create-zitadel-session'
22

33
interface Login {
44
userId: string

Diff for: apps/web/src/app/portal/(unauthenticated)/api/auth/callback/lib/register.ts renamed to apps/web/src/app/portal/(hero)/(unauthenticated)/api/auth/callback/lib/register.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getUserServiceClient } from 'src/app/portal/_common/lib/zitadel-client'
2-
import type { IdpIntent } from '../../../../../_common/lib/get-idp-intent'
2+
import type { IdpIntent } from '../../../../../../_common/lib/get-idp-intent'
33

44
export async function register(idpIntent: IdpIntent) {
55
const userServiceClient = getUserServiceClient()

Diff for: apps/web/src/app/portal/(unauthenticated)/api/auth/callback/route.ts renamed to apps/web/src/app/portal/(hero)/(unauthenticated)/api/auth/callback/route.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
getSession,
77
} from 'src/app/portal/_common/lib/client-config'
88
import { z } from 'zod'
9-
import { getIdpIntent } from '../../../../_common/lib/get-idp-intent'
10-
import { getSessionServiceClient } from '../../../../_common/lib/zitadel-client'
9+
import { getIdpIntent } from '../../../../../_common/lib/get-idp-intent'
10+
import { getSessionServiceClient } from '../../../../../_common/lib/zitadel-client'
1111
import { getUserById } from './lib/get-user-by-id'
1212
import { login } from './lib/login'
1313
import { register } from './lib/register'
@@ -46,7 +46,7 @@ async function GET(req: NextRequest) {
4646
if (e instanceof Error && 'code' in e) {
4747
// User already exists
4848
if (e.code === 6) {
49-
return redirect('/portal/login?error_tag=oauthAlreadyExists')
49+
return redirect('/portal?error_tag=oauthAlreadyExists')
5050
}
5151
}
5252
return new Response('An unknown error occured', { status: 500 })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
'use server'
2+
3+
import { TextQueryMethod } from '@zitadel/proto/zitadel/object/v2/object_pb'
4+
import { getBaseUrl } from 'src/app/portal/_common/lib/get-base-url'
5+
import { getAdminStyroClient } from 'src/app/portal/_common/lib/styro/styro-client'
6+
import { getUserServiceClient } from 'src/app/portal/_common/lib/zitadel-client'
7+
import { forgotPasswordFormSchema } from './forgot-password-form-schema'
8+
9+
export type FormState =
10+
| {
11+
error: string
12+
}
13+
| {
14+
error: string
15+
field: keyof (typeof forgotPasswordFormSchema)['_output']
16+
}
17+
| {
18+
success: true
19+
}
20+
21+
export async function forgotPasswordAction(data: FormData): Promise<FormState> {
22+
const formData = Object.fromEntries(data.entries())
23+
const result = forgotPasswordFormSchema.safeParse(formData)
24+
25+
if (!result.success) {
26+
return { error: 'Invalid form data' }
27+
}
28+
29+
const userServiceClient = getUserServiceClient()
30+
let userResponse
31+
try {
32+
userResponse = await userServiceClient.listUsers({
33+
queries: [
34+
{
35+
$typeName: 'zitadel.user.v2.SearchQuery',
36+
query: {
37+
case: 'emailQuery',
38+
value: {
39+
$typeName: 'zitadel.user.v2.EmailQuery',
40+
emailAddress: result.data.email,
41+
method: TextQueryMethod.CONTAINS_IGNORE_CASE,
42+
},
43+
},
44+
},
45+
],
46+
query: {
47+
limit: 1,
48+
},
49+
})
50+
} catch (e) {
51+
console.error(e)
52+
return { error: 'Failed to reset password' }
53+
}
54+
55+
if (userResponse.result.length === 0) {
56+
return {
57+
field: 'email',
58+
error:
59+
"We couldn't find an account with that email address. Please try again or register an account.",
60+
}
61+
}
62+
63+
let resetResponse
64+
try {
65+
resetResponse = await userServiceClient.passwordReset({
66+
$typeName: 'zitadel.user.v2.PasswordResetRequest',
67+
medium: {
68+
case: 'returnCode',
69+
value: {
70+
$typeName: 'zitadel.user.v2.ReturnPasswordResetCode',
71+
},
72+
},
73+
userId: userResponse.result[0].userId,
74+
})
75+
} catch (e) {
76+
console.error(e)
77+
return { error: 'Failed to reset password' }
78+
}
79+
80+
if (!resetResponse.verificationCode) {
81+
return { error: 'Failed to reset password' }
82+
}
83+
84+
const client = getAdminStyroClient()
85+
try {
86+
await client.postAdminFrontendEmail({
87+
postAdminFrontendEmailRequest: {
88+
email: {
89+
type: 'reset_password',
90+
frontend: {
91+
baseUrl: await getBaseUrl(),
92+
},
93+
reset: {
94+
email: result.data.email,
95+
userId: userResponse.result[0].userId,
96+
code: resetResponse.verificationCode,
97+
},
98+
},
99+
},
100+
})
101+
} catch (e) {
102+
console.error(e)
103+
return { error: 'Failed to send email' }
104+
}
105+
106+
return { success: true }
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from 'zod'
2+
3+
export const forgotPasswordFormSchema = z.object({
4+
email: z.string().email(),
5+
})

0 commit comments

Comments
 (0)