Skip to content

Commit

Permalink
[#UR94] - add open support dropdown button UI+logic
Browse files Browse the repository at this point in the history
1. UX improved when login with OAuth
2. And ohter minor changes made in previous commits
nicitaacom authored Nov 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents a915389 + 90ef6cb commit 0a5324c
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions app/(auth)/AuthModal/AuthModal.tsx
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ export function AuthModal({ label }: AdminModalProps) {
if (isRecoverCompleted) router.push("?modal=AuthModal&variant=recoverCompleted")

function recoverCompletedHandler() {
// TODO - do I need to setUser() ?
setIsRecoverCompleted(true)
router.refresh()
}
@@ -366,13 +367,14 @@ export function AuthModal({ label }: AdminModalProps) {
response.data.user.email,
response.data.user.user_metadata.avatar_url ||
response.data.user?.identities![0]?.identity_data?.avatar_url ||
response.data.user?.identities![1]?.identity_data?.avatar_url,
response.data.user?.identities![1]?.identity_data?.avatar_url ||
"",
)

displayResponseMessage(
<div className="text-success flex flex-col justify-center items-center">
Your password changed - you may close this window
<Timer label="I close this modal in" seconds={7} action={() => router.replace("/")} />
Your password changed - Delete email
<Timer label="I close this window in" seconds={5} action={() => window.close()} />
</div>,
)
} catch (error) {
2 changes: 1 addition & 1 deletion app/(auth)/auth/callback/credentials/route.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ export async function GET(request: Request) {
// Trigger pusher to 'auth:completed' to show in another tab message like 'Authencication completed - thank you'
// TODO - check it - because might possible error with setting data in localstorage
// I mean it localstorage will be updated only on 'auth completed you may close this page' but not in actual first page
pusherServer.trigger(email, "auth:completed", response.data.user)
pusherServer.trigger(email, "auth:completed", null)

return NextResponse.redirect(
`${requestUrl.origin}/auth/completed?code=${code}
4 changes: 2 additions & 2 deletions app/(auth)/auth/callback/recover/route.ts
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@ export async function GET(request: Request) {
if (update_provider_error) throw update_provider_error
}

// 4. Save email in cookies to trigger pusher for this channel (api/auth/recover)
cookies().set("email", response.data.user.email)
// 4. Save email in cookies to trigger pusher for this channel (api/auth/recover) (expires in 5 min)
cookies().set("email", response.data.user.email, { expires: 300000 })

return NextResponse.redirect(`${requestUrl.origin}?modal=AuthModal&variant=resetPassword&code=${code}`)
} else {
7 changes: 5 additions & 2 deletions app/(auth)/auth/completed/page.tsx
Original file line number Diff line number Diff line change
@@ -22,12 +22,15 @@ export default function AuthCompleted() {

useEffect(() => {
userStore.setUser(userId ?? "", username ?? "", email ?? "", avatarUrl ?? "")

if (provider === "google" || provider === "twitter") return router.replace("/")
//to prevent error about too many re-renders
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

if (provider === "google" || provider === "twitter") {
router.replace("/")
return null
}

if (!params) {
const error_description = encodeURIComponent("auth not completed")
return router.push(`/error?error=${error_description}`)
3 changes: 1 addition & 2 deletions app/api/auth/recover/route.ts
Original file line number Diff line number Diff line change
@@ -18,8 +18,7 @@ export async function POST(req: Request) {
}
throw new Error(error.message)
}

pusherServer.trigger(body.email, "recover:completed", "")
pusherServer.trigger(body.email, "recover:completed", null)
return NextResponse.json({ user: data.user })
} catch (error) {
if (error instanceof Error) {

0 comments on commit 0a5324c

Please sign in to comment.