Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: login right after register #40

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading