Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TelegramIcon } from "@oko-wallet/oko-common-ui/icons/telegram_icon";
import { XIcon } from "@oko-wallet/oko-common-ui/icons/x_icon";
import { AppleIcon } from "@oko-wallet/oko-common-ui/icons/apple_icon";
import { MailboxIcon } from "@oko-wallet/oko-common-ui/icons/mailbox";
import { OkoLogoWithNameIcon } from "@oko-wallet-common-ui/icons/oko_logo_with_name_icon";
import { OkoLogoWithNameIcon } from "@oko-wallet/oko-common-ui/icons/oko_logo_with_name_icon";

import styles from "./login_widget.module.scss";
import type { LoginMethod } from "@oko-wallet-demo-web/types/login";
Expand All @@ -30,67 +30,29 @@ export const LoginDefaultView: FC<LoginDefaultViewProps> = ({
<Logo theme={"light"} width={84} height={32} />
</div>

{/* @TODO: remove comment after other socials are implemented for production */}
{/* <Button
variant="secondary"
size="md"
fullWidth
onClick={() => onSignIn("email")}
>
<MailboxIcon size={20} color={"var(--fg-tertiary)"} />
<Spacing width={2} />
Email
</Button> */}

<Button
variant="secondary"
size="md"
fullWidth
onClick={() => onSignIn("google")}
>
<GoogleIcon width={20} height={20} />
Google
</Button>

{/* @TODO: remove dividerRow after email login is implemented for production */}
<div className={styles.dividerRow}>
<div className={styles.line} />
<Typography tagType="span" size="xs" weight="medium" color="quaternary">
Coming soon
</Typography>
<div className={styles.line} />
</div>

<div className={styles.loginMethodsWrapper}>
{/* @TODO: remove emailLoginMethod after email login is implemented for production */}
<div className={styles.emailLoginMethod}>
<MailboxIcon size={20} color={"var(--fg-quaternary)"} />
<input
placeholder="[email protected]"
value=""
readOnly
className={styles.emailInput}
type="email"
disabled
/>
<Button
variant="ghost"
size="md"
className={styles.loginButton}
disabled
>
Next
</Button>
</div>
<Button
variant="secondary"
size="md"
fullWidth
onClick={() => onSignIn("email")}
>
<MailboxIcon size={20} color={"var(--fg-tertiary)"} />
<Spacing width={2} />
Email
</Button>

<Button
variant="secondary"
size="md"
fullWidth
onClick={onShowSocials}
// @TODO: remove disabled after other socials are implemented for production
disabled
onClick={() => onSignIn("google")}
>
<GoogleIcon width={20} height={20} />
Google
</Button>

<Button variant="secondary" size="md" fullWidth onClick={onShowSocials}>
<div className={styles.socialIconWrapper}>
<XIcon size={16} />
<TelegramIcon size={16} />
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions apps/demo_web/src/state/user_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export const useUserInfoState = create(
setUserInfo: (info) => {
set({
authType: info.authType,
email: info.email,
email: info.email ?? null,
publicKey: info.publicKey,
name: info.name ?? null,
isSignedIn: !!(info.email && info.publicKey),
isSignedIn: !!info.publicKey,
});
},
clearUserInfo: () => {
Expand Down
9 changes: 6 additions & 3 deletions backend/openapi/src/tss/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ export const SignInResponseSchema = registry.register(
}),
user: z
.object({
email: z.string().openapi({
description: "User email address",
}),
wallet_id: z.string().openapi({
description: "Unique wallet identifier",
}),
public_key: z.string().openapi({
description: "Public key in hex format",
}),
user_identifier: z.string().openapi({
description: "User identifier",
}),
email: z.string().nullable().openapi({
description: "User email address (nullable)",
}),
name: z.string().nullable().openapi({
description:
"User name (nullable) Only for OAuth providers that support it",
Expand Down
5 changes: 5 additions & 0 deletions backend/tss_api/src/api/keygen/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe("keygen_test", () => {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: "[email protected]",
email: "[email protected]",
keygen_2,
};
Expand Down Expand Up @@ -196,6 +197,7 @@ describe("keygen_test", () => {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: "[email protected]",
email: "[email protected]",
keygen_2: {
public_key: keygen_outputs[Participant.P1].public_key,
Expand Down Expand Up @@ -237,6 +239,7 @@ describe("keygen_test", () => {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: "[email protected]",
email: "[email protected]",
keygen_2: {
public_key: keygen_outputs[Participant.P1].public_key,
Expand Down Expand Up @@ -274,6 +277,7 @@ describe("keygen_test", () => {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: "[email protected]",
email: "[email protected]",
keygen_2: {
public_key: keygen_outputs[Participant.P1].public_key,
Expand Down Expand Up @@ -313,6 +317,7 @@ describe("keygen_test", () => {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: "[email protected]",
email: "[email protected]",
keygen_2: {
public_key: keygen_outputs[Participant.P1].public_key,
Expand Down
17 changes: 11 additions & 6 deletions backend/tss_api/src/api/keygen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ export async function runKeygen(
encryptionSecret: string,
): Promise<OkoApiResponse<SignInResponse>> {
try {
const { auth_type, email, keygen_2, name } = keygenRequest;
const { auth_type, user_identifier, keygen_2, email, name } = keygenRequest;

const getUserRes = await getUserByEmailAndAuthType(db, email, auth_type);
const getUserRes = await getUserByEmailAndAuthType(
db,
user_identifier,
auth_type,
);
if (getUserRes.success === false) {
return {
success: false,
Expand Down Expand Up @@ -69,7 +73,7 @@ export async function runKeygen(
};
}
} else {
const createUserRes = await createUser(db, email, auth_type);
const createUserRes = await createUser(db, user_identifier, auth_type);
if (createUserRes.success === false) {
return {
success: false,
Expand Down Expand Up @@ -123,7 +127,7 @@ export async function runKeygen(
const activeKSNodes = getActiveKSNodesRes.data;

const checkKeyshareFromKSNodesRes = await checkKeyShareFromKSNodes(
email,
user_identifier,
publicKeyBytes,
activeKSNodes,
auth_type,
Expand Down Expand Up @@ -200,7 +204,7 @@ export async function runKeygen(

const tokenResult = generateUserToken({
wallet_id: wallet.wallet_id,
email: email,
email: user_identifier,
jwt_config: jwtConfig,
});

Expand All @@ -217,9 +221,10 @@ export async function runKeygen(
data: {
token: tokenResult.data.token,
user: {
email: email,
wallet_id: wallet.wallet_id,
public_key: keygen_2.public_key,
user_identifier: user_identifier,
email: email ?? null,
name: name ?? null,
},
},
Expand Down
1 change: 1 addition & 0 deletions backend/tss_api/src/api/presign/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async function setUpTssStage(pool: Pool) {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: email,
email: email,
keygen_2,
};
Expand Down
1 change: 1 addition & 0 deletions backend/tss_api/src/api/sign/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async function setUpTssStage(pool: Pool) {

const keygenRequest: KeygenRequest = {
auth_type: "google",
user_identifier: email,
email: email,
keygen_2,
};
Expand Down
14 changes: 10 additions & 4 deletions backend/tss_api/src/api/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ import { checkKeyShareFromKSNodes } from "@oko-wallet-tss-api/api/ks_node";

export async function signIn(
db: Pool,
email: string,
user_identifier: string,
auth_type: AuthType,
jwt_config: {
secret: string;
expires_in: string;
},
email?: string,
name?: string,
): Promise<OkoApiResponse<SignInResponse>> {
try {
const getUserRes = await getUserByEmailAndAuthType(db, email, auth_type);
const getUserRes = await getUserByEmailAndAuthType(
db,
user_identifier,
auth_type,
);
if (getUserRes.success === false) {
return {
success: false,
Expand All @@ -53,7 +58,7 @@ export async function signIn(
return {
success: false,
code: "USER_NOT_FOUND",
msg: `User not found: ${email} (auth_type: ${auth_type})`,
msg: `User not found: ${user_identifier} (auth_type: ${auth_type})`,
};
}

Expand Down Expand Up @@ -96,9 +101,10 @@ export async function signIn(
data: {
token: tokenResult.data.token,
user: {
email: getUserRes.data.email,
wallet_id: walletRes.data.wallet_id,
public_key: walletRes.data.public_key.toString("hex"),
user_identifier: user_identifier,
email: email ?? null,
name: name ?? null,
},
},
Expand Down
2 changes: 2 additions & 0 deletions backend/tss_api/src/middleware/auth0_auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export async function auth0AuthMiddleware(

res.locals.oauth_user = {
type: "auth0" as AuthType,
// in auth0, use email as identifier
user_identifier: result.data.email,
email: result.data.email,
};

Expand Down
5 changes: 3 additions & 2 deletions backend/tss_api/src/middleware/discord_auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export async function discordAuthMiddleware(

res.locals.oauth_user = {
type: "discord" as AuthType,
// in discord, use discord id as email with prefix
email: `discord_${result.data.id}`,
// in discord, use discord id as identifier with prefix
user_identifier: `discord_${result.data.id}`,
email: result.data.email,
name: result.data.username,
};

Expand Down
Loading