Skip to content

Commit

Permalink
fix: login right after register
Browse files Browse the repository at this point in the history
  • Loading branch information
seelengxd committed Sep 24, 2024
1 parent 9f3ba2a commit bb87d69
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions backend/src/auth/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@


@router.post("/signup")
def sign_up(data: SignUpData, session=Depends(get_session)):
def sign_up(
data: SignUpData, response: Response, session=Depends(get_session)
) -> Token:
existing_user = session.scalars(
select(User).where(User.email == data.email)
).first()
Expand All @@ -52,8 +54,9 @@ def sign_up(data: SignUpData, session=Depends(get_session)):
)
session.add(new_user)
session.commit()
session.refresh(new_user)

return
return create_token(new_user, response)


@router.post("/login")
Expand Down
3 changes: 1 addition & 2 deletions backend/src/events/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def add_event_to_db(event: EventLLM) -> bool:
eventORM = session.scalars(
select(Event).where(
Event.title == event.title,
Event.description == Event.description,
Event.duplicate == event.duplicate,
Event.description == event.description,
Event.is_singapore == event.is_singapore,
Event.original_article_id == event.original_article_id,
)
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/(unauthenticated)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
import { Box } from "@/components/ui/box";
import { Button } from "@/components/ui/button";
import { Form } from "@/components/ui/form";
import { useUserStore } from "@/store/user/user-store-provider";

const registerFormSchema = z.object({
email: z.string().email("Invalid email address"),
Expand All @@ -31,6 +32,7 @@ type RegisterForm = z.infer<typeof registerFormSchema>;

function RegisterPage() {
const router = useRouter();
const setLoggedIn = useUserStore((state) => state.setLoggedIn);
const [isError, setIsError] = useState<boolean>(false);
const form = useForm<RegisterForm>({
resolver: zodResolver(registerFormSchema),
Expand All @@ -47,6 +49,7 @@ function RegisterPage() {
setIsError(true);
} else {
setIsError(false);
setLoggedIn(response.data.user);
router.push("/login");
}
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export type SignUpAuthSignupPostData = {
body: SignUpData;
};

export type SignUpAuthSignupPostResponse = (unknown);
export type SignUpAuthSignupPostResponse = (Token);

export type SignUpAuthSignupPostError = (HTTPValidationError);

Expand Down

0 comments on commit bb87d69

Please sign in to comment.