fix: "Not you? Log in" on JoinPage now clears session before navigating
The link was bouncing back to JoinPage because AuthRedirect on /login saw the existing token and redirected right back. Now calls logout() first so the login form actually renders.
This commit is contained in:
@@ -17,6 +17,7 @@ export function JoinPage() {
|
|||||||
const user = useAuthStore((s) => s.user);
|
const user = useAuthStore((s) => s.user);
|
||||||
const loadUser = useAuthStore((s) => s.loadUser);
|
const loadUser = useAuthStore((s) => s.loadUser);
|
||||||
const isAuthLoading = useAuthStore((s) => s.isLoading);
|
const isAuthLoading = useAuthStore((s) => s.isLoading);
|
||||||
|
const logout = useAuthStore((s) => s.logout);
|
||||||
const joinByCode = useSpaceStore((s) => s.joinByCode);
|
const joinByCode = useSpaceStore((s) => s.joinByCode);
|
||||||
const connectToRemote = useInstanceStore((s) => s.connectToRemote);
|
const connectToRemote = useInstanceStore((s) => s.connectToRemote);
|
||||||
const loginToRemote = useInstanceStore((s) => s.loginToRemote);
|
const loginToRemote = useInstanceStore((s) => s.loginToRemote);
|
||||||
@@ -234,7 +235,7 @@ export function JoinPage() {
|
|||||||
<div className="text-center mb-6">
|
<div className="text-center mb-6">
|
||||||
<div className="flex justify-center mb-4">
|
<div className="flex justify-center mb-4">
|
||||||
<Avatar
|
<Avatar
|
||||||
src={preview.icon ? (parsed?.origin ? `${parsed.origin}/api/uploads/${preview.icon}` : `/api/uploads/${preview.icon}`) : null}
|
src={preview.icon ? (parsed?.origin ? `${parsed.origin}/api/uploads/${preview.icon}` : preview.icon) : null}
|
||||||
name={preview.spaceName}
|
name={preview.spaceName}
|
||||||
size={72}
|
size={72}
|
||||||
avatarColor={preview.avatarColor}
|
avatarColor={preview.avatarColor}
|
||||||
@@ -263,14 +264,46 @@ export function JoinPage() {
|
|||||||
{/* Phase: preview — main join UI */}
|
{/* Phase: preview — main join UI */}
|
||||||
{phase === 'preview' && (
|
{phase === 'preview' && (
|
||||||
<>
|
<>
|
||||||
{token ? (
|
{token && user ? (
|
||||||
/* Authenticated user */
|
/* Authenticated user — show identity card + join */
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center gap-3 bg-surface-input rounded-lg p-3">
|
||||||
|
<Avatar
|
||||||
|
src={user.avatar || null}
|
||||||
|
name={user.displayName || user.username}
|
||||||
|
size={40}
|
||||||
|
avatarColor={user.avatarColor}
|
||||||
|
/>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-txt-primary font-medium text-sm truncate">{user.displayName || user.username}</p>
|
||||||
|
<p className="text-txt-tertiary text-xs truncate">@{user.username}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleJoin}
|
||||||
|
disabled={isJoining}
|
||||||
|
className="w-full py-2.5 bg-accent-primary hover:bg-accent-primary/80 text-white font-medium rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
{isJoining ? 'Joining...' : `Join as ${user.displayName || user.username}`}
|
||||||
|
</button>
|
||||||
|
<p className="text-center text-xs text-txt-tertiary">
|
||||||
|
Not you?{' '}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => { logout(); navigate(`/login${redirectParam}`); }}
|
||||||
|
className="text-accent-primary hover:underline"
|
||||||
|
>
|
||||||
|
Log in
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : token ? (
|
||||||
|
/* Token exists but user still loading */
|
||||||
<button
|
<button
|
||||||
onClick={handleJoin}
|
disabled
|
||||||
disabled={isJoining || isAuthLoading}
|
|
||||||
className="w-full py-2.5 bg-accent-primary hover:bg-accent-primary/80 text-white font-medium rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
className="w-full py-2.5 bg-accent-primary hover:bg-accent-primary/80 text-white font-medium rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
{isAuthLoading ? 'Loading...' : isJoining ? 'Joining...' : 'Join Space'}
|
Loading...
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
/* Unauthenticated user */
|
/* Unauthenticated user */
|
||||||
@@ -349,7 +382,7 @@ export function JoinPage() {
|
|||||||
{/* Identity card */}
|
{/* Identity card */}
|
||||||
<div className="flex items-center gap-3 bg-surface-input rounded-lg p-3 mb-3">
|
<div className="flex items-center gap-3 bg-surface-input rounded-lg p-3 mb-3">
|
||||||
<Avatar
|
<Avatar
|
||||||
src={user?.avatar ? `/api/uploads/${user.avatar}` : null}
|
src={user?.avatar || null}
|
||||||
name={user?.displayName || user?.username || '?'}
|
name={user?.displayName || user?.username || '?'}
|
||||||
size={40}
|
size={40}
|
||||||
avatarColor={user?.avatarColor}
|
avatarColor={user?.avatarColor}
|
||||||
|
|||||||
Reference in New Issue
Block a user