Skip to content

Commit

Permalink
Added amplify logic to handle signup
Browse files Browse the repository at this point in the history
  • Loading branch information
AA25 committed Jun 9, 2024
1 parent 9adaa6b commit 988136c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/lib/cognitoActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
signIn,
signOut,
confirmSignIn
confirmSignIn,
signUp
} from "aws-amplify/auth";
import { redirect } from "next/navigation";

Expand All @@ -20,6 +21,9 @@ export async function handleSignIn(
challengeResponse: "1234567",
})
}
if (nextStep.signInStep === "CONFIRM_SIGN_UP") {
return "User needs to request Admin to confirm account";
}
} catch (error) {
console.log(error);
return "handleSignIn error";
Expand All @@ -37,3 +41,30 @@ export async function handleSignOut() {
}
redirect("/auth/login");
}

export async function handleSignUp(
previousState: string | undefined | null,
formData: FormData
){
try {
const { isSignUpComplete, userId, nextStep } = await signUp({
username: String(formData.get("email")),
password: String(formData.get("password")),
options: {
userAttributes: {
email: String(formData.get("email")),
given_name: String(formData.get("given_name")),
family_name: String(formData.get("family_name")),
address: String(formData.get("address")),
},
autoSignIn: true,
},
});
console.log(`isSignUpComplete: ${isSignUpComplete}`);
console.log(`nextStep: ${JSON.stringify(nextStep)}`);
} catch (error) {
console.log(error);
return "handleSignUp error";
}
redirect("/auth/login")
}

0 comments on commit 988136c

Please sign in to comment.