commit before i break things
This commit is contained in:
@@ -50,7 +50,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
let subscribedSubjectIds: string[] = [];
|
||||
if (res.userId) {
|
||||
try {
|
||||
const dto = await authApi.getUser(res.userId, res.token);
|
||||
const dto = await authApi.getUser( res.token);
|
||||
subscribedSubjectIds = dto.subjectSet?.map((s) => s.id) ?? [];
|
||||
} catch {
|
||||
// aaaa
|
||||
@@ -67,7 +67,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const register = async (payload: RegisterPayload) => {
|
||||
await authApi.register(payload);
|
||||
await login({ email: payload.email, password: payload.password });
|
||||
await login({
|
||||
email: payload.email.trim(),
|
||||
password: payload.password.trim(),
|
||||
});
|
||||
};
|
||||
|
||||
const updateUser = async (newEmail?: string, newPassword?: string) => {
|
||||
@@ -91,7 +94,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const subscribe = async (subjectId: string) => {
|
||||
if (!user) return;
|
||||
const dto = await subscriptionsApi.subscribe(user.id, subjectId, user.token);
|
||||
const dto = await subscriptionsApi.subscribe( subjectId, user.token);
|
||||
const updated = {
|
||||
...user,
|
||||
subscribedSubjectIds: dto.subjectSet?.map((s) => s.id) ?? [...user.subscribedSubjectIds, subjectId],
|
||||
@@ -101,7 +104,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const unsubscribe = async (subjectId: string) => {
|
||||
if (!user) return;
|
||||
const dto = await subscriptionsApi.unsubscribe(user.id, subjectId, user.token);
|
||||
const dto = await subscriptionsApi.unsubscribe( subjectId, user.token);
|
||||
const updated = {
|
||||
...user,
|
||||
subscribedSubjectIds: dto.subjectSet?.map((s) => s.id) ?? user.subscribedSubjectIds.filter((id) => id !== subjectId),
|
||||
|
||||
@@ -25,13 +25,19 @@ export default function AuthGate({ onSuccess }: { onSuccess?: () => void }) {
|
||||
const accent = dark ? "#E07B45" : "#C4622D";
|
||||
|
||||
const submit = async () => {
|
||||
|
||||
const trimmedEmail = email.trim();
|
||||
const trimmedPassword = password.trim();
|
||||
|
||||
|
||||
|
||||
setError("");
|
||||
if (!email || !password) { setError("Please fill in all fields."); return; }
|
||||
if (!trimmedEmail || !trimmedPassword) { setError("Please fill in all fields."); return; }
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
if (mode === "login") await login({ email, password });
|
||||
else await register({ email, password, name });
|
||||
if (mode === "login") await login({ email:trimmedEmail, password:trimmedPassword});
|
||||
else await register({ email: trimmedEmail,password:trimmedPassword , name });
|
||||
onSuccess?.();
|
||||
} catch (e: any) {
|
||||
setError(e.message ?? "Something went wrong.");
|
||||
|
||||
@@ -103,8 +103,15 @@ export type RegisterPayload = { email: string; password: string; name?: string }
|
||||
export const authApi = {
|
||||
login: (p: LoginPayload) => post<JwtResponse>("/login", p),
|
||||
register: (p: RegisterPayload) => post<UserDTO>("/register", p),
|
||||
getUser: (userId: string, token: string) => get<UserDTO>(`/users/${userId}`, token),
|
||||
updateUser: (body: UserUpdateDTO, token: string) => request<UserDTO>("PUT", "/users", token, body),
|
||||
|
||||
getUser: (token: string) =>
|
||||
get<UserDTO>("/users/me", token),
|
||||
|
||||
updateUser: (body: UserUpdateDTO, token: string) =>
|
||||
request<UserDTO>("PUT", "/users/me", token, body),
|
||||
|
||||
deleteUser: (token: string) =>
|
||||
del<void>("/users/me", token),
|
||||
};
|
||||
|
||||
|
||||
@@ -114,19 +121,20 @@ export const subjectsApi = {
|
||||
};
|
||||
|
||||
export const subscriptionsApi = {
|
||||
subscribe: (userId: string, subjectId: string, token: string) =>
|
||||
subscribe: (subjectId: string, token: string) =>
|
||||
put<UserDTO>(
|
||||
`/users/${userId}/subjects/${subjectId}`,
|
||||
{}, // body placeholder
|
||||
`/users/me/subjects/${subjectId}`,
|
||||
{},
|
||||
token
|
||||
),
|
||||
|
||||
unsubscribe: (userId: string, subjectId: string, token: string) =>
|
||||
unsubscribe: (subjectId: string, token: string) =>
|
||||
del<UserDTO>(
|
||||
`/users/${userId}/subjects/${subjectId}`,
|
||||
`/users/me/subjects/${subjectId}`,
|
||||
token
|
||||
),
|
||||
};
|
||||
|
||||
export const entriesApi = {
|
||||
getEntries: (params: { subjectId?: string; groupName?: string; page?: number }) =>
|
||||
get<SpringPage<Entry>>("/entries", undefined, params),
|
||||
|
||||
Reference in New Issue
Block a user