chore: cleanup — remove legacy redirect shims and localStorage token storage
- Delete 19 redirect alias pages (sign-in/signin/sign-up/signup, /users/* aliases, /companies/* aliases, /users/onboarding/* aliases) — legacy Next.js migration artifacts that are no longer needed - Remove localStorage token functions (getAccessToken, setTokens, clearTokens, fetchWithAuth) from lib/http.ts — violates memory-only token strategy - Fix auth/verification: replace setTokens + manual fetch with login() from auth.ts - Fix ProfileWidget: replace fetchWithAuth with plain fetch (calls server routes) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ea31bcb1ff
commit
c14bf111a8
22 changed files with 5 additions and 197 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { createSignal, createResource, Show, onMount } from 'solid-js';
|
||||
import { fetchWithAuth } from '~/lib/http';
|
||||
|
||||
export default function ProfileWidget(props: { roleKey: string }) {
|
||||
const [loading, setLoading] = createSignal(false);
|
||||
|
|
@ -10,7 +9,7 @@ export default function ProfileWidget(props: { roleKey: string }) {
|
|||
const [formData, setFormData] = createSignal<Record<string, any>>({});
|
||||
|
||||
const fetchProfile = async (roleKey: string) => {
|
||||
const res = await fetchWithAuth(`/api/users/profile/get?roleKey=${roleKey}`);
|
||||
const res = await fetch(`/api/users/profile/get?roleKey=${roleKey}`);
|
||||
if (!res.ok) throw new Error('Failed to load profile');
|
||||
const payload = await res.json();
|
||||
if (payload.data) {
|
||||
|
|
@ -32,7 +31,7 @@ export default function ProfileWidget(props: { roleKey: string }) {
|
|||
setSuccess(false);
|
||||
|
||||
try {
|
||||
const res = await fetchWithAuth(`/api/users/profile/update?roleKey=${props.roleKey}`, {
|
||||
const res = await fetch(`/api/users/profile/update?roleKey=${props.roleKey}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(formData())
|
||||
|
|
|
|||
|
|
@ -33,67 +33,3 @@ export function getServiceUrlForRole(roleKey: string | null | undefined): string
|
|||
}
|
||||
}
|
||||
|
||||
export function getAccessToken(): string | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
return window.localStorage.getItem('access_token');
|
||||
}
|
||||
|
||||
export function setTokens(accessToken: string, refreshToken: string) {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.localStorage.setItem('access_token', accessToken);
|
||||
window.localStorage.setItem('refresh_token', refreshToken);
|
||||
}
|
||||
|
||||
export function clearTokens() {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.localStorage.removeItem('access_token');
|
||||
window.localStorage.removeItem('refresh_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* An HTTP client that automatically adds Bearer tokens and handles
|
||||
* 401 Unauthorized errors by attempting token refresh.
|
||||
*/
|
||||
export async function fetchWithAuth(url: string, options: RequestInit = {}): Promise<Response> {
|
||||
const token = getAccessToken();
|
||||
const headers = new Headers(options.headers || {});
|
||||
|
||||
if (token) {
|
||||
headers.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
|
||||
// 1. Make Original Request
|
||||
let response = await fetch(url, { ...options, headers });
|
||||
|
||||
// 2. Refresh Token on 401
|
||||
if (response.status === 401) {
|
||||
if (typeof window === 'undefined') return response;
|
||||
const refreshToken = window.localStorage.getItem('refresh_token');
|
||||
|
||||
if (refreshToken) {
|
||||
try {
|
||||
const refreshRes = await fetch(`${RUST_API_URL}/api/auth/refresh`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ refresh_token: refreshToken })
|
||||
});
|
||||
|
||||
if (refreshRes.ok) {
|
||||
const payload = await refreshRes.json();
|
||||
setTokens(payload.access_token, payload.refresh_token);
|
||||
|
||||
// Retry Original Request
|
||||
headers.set('Authorization', `Bearer ${payload.access_token}`);
|
||||
response = await fetch(url, { ...options, headers });
|
||||
} else {
|
||||
// Refresh Failed -> Session expired
|
||||
clearTokens();
|
||||
}
|
||||
} catch (err) {
|
||||
clearTokens();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { A, useNavigate, useSearchParams } from '@solidjs/router';
|
||||
import { createMemo, createSignal, For, onMount } from 'solid-js';
|
||||
import { intentToOnboardingPath, normalizeIntent, readCanonicalIntent, saveCanonicalIntent } from '~/lib/auth-intent';
|
||||
import { setTokens } from '~/lib/http';
|
||||
import { login } from '~/lib/auth';
|
||||
import PublicBackground from '~/components/PublicBackground';
|
||||
|
||||
const OTP_LENGTH = 6;
|
||||
|
|
@ -124,25 +124,7 @@ export default function VerificationPage() {
|
|||
|
||||
try {
|
||||
// Auto login after successful backend OTP verification
|
||||
const loginResponse = await fetch('/api/users/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ email: pending.email, password: pending.password }),
|
||||
});
|
||||
const loginPayload = await loginResponse.json().catch(() => ({}));
|
||||
|
||||
if (!loginResponse.ok || !loginPayload?.success) {
|
||||
const loginError = getApiErrorMessage(loginPayload);
|
||||
setError(loginError || 'Email verified and account created. Please sign in to continue.');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save tokens using our utility
|
||||
if (loginPayload.access_token && loginPayload.refresh_token) {
|
||||
setTokens(loginPayload.access_token, loginPayload.refresh_token);
|
||||
}
|
||||
await login(pending.email, pending.password);
|
||||
|
||||
window.localStorage.removeItem(PENDING_REGISTER_KEY);
|
||||
window.localStorage.removeItem(DEV_VERIFICATION_CODE_KEY);
|
||||
|
|
@ -150,7 +132,7 @@ export default function VerificationPage() {
|
|||
return;
|
||||
|
||||
} catch (err: any) {
|
||||
setError('Login failed: ' + err.message);
|
||||
setError(err.message || 'Email verified and account created. Please sign in to continue.');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function CompaniesApplicationsAlias() {
|
||||
return <Navigate href="/dashboard/applications" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function CompaniesFeedbackAlias() {
|
||||
return <Navigate href="/support" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function CompaniesJobPostingsAlias() {
|
||||
return <Navigate href="/dashboard/jobs" />;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
import { useNavigate } from '@solidjs/router';
|
||||
import { onMount } from 'solid-js';
|
||||
|
||||
export default function CompaniesSupportAliasPage() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
onMount(() => {
|
||||
navigate('/support', { replace: true });
|
||||
});
|
||||
|
||||
return <p>Redirecting to company support...</p>;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function CompaniesTracecoinsAlias() {
|
||||
return <Navigate href="/dashboard/wallet" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import LoginPage from '~/routes/auth/login/index';
|
||||
|
||||
export default function SignInAliasPage() {
|
||||
return <LoginPage />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import RegisterPage from '~/routes/auth/register/index';
|
||||
|
||||
export default function SignUpAliasPage() {
|
||||
return <RegisterPage />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import LoginPage from '~/routes/auth/login/index';
|
||||
|
||||
export default function SigninAliasPage() {
|
||||
return <LoginPage />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import RegisterPage from '~/routes/auth/register/index';
|
||||
|
||||
export default function SignupAliasPage() {
|
||||
return <RegisterPage />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersDashboardAlias() {
|
||||
return <Navigate href="/dashboard" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersLeadsAlias() {
|
||||
return <Navigate href="/dashboard/requests" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersNotificationsAlias() {
|
||||
return <Navigate href="/dashboard/notifications" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersOnboardingAlias() {
|
||||
return <Navigate href="/onboarding" />;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
import { onMount } from 'solid-js';
|
||||
import { useNavigate } from '@solidjs/router';
|
||||
|
||||
export default function JobSeekerAliasRoute() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
onMount(() => {
|
||||
navigate('/users/onboarding/job-seeker', { replace: true });
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersRoleSelectionAlias() {
|
||||
return <Navigate href="/users/choose-role" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersProfileAlias() {
|
||||
return <Navigate href="/dashboard/profile" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersSettingsAlias() {
|
||||
return <Navigate href="/dashboard/settings" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersSupportAlias() {
|
||||
return <Navigate href="/support" />;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Navigate } from '@solidjs/router';
|
||||
|
||||
export default function UsersVerificationStatusAlias() {
|
||||
return <Navigate href="/pending" />;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue