@yackey-labs/yauth-ui-solidjs 0.2.6 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yackey-labs/yauth-ui-solidjs",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/yackey-labs/yauth"
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@simplewebauthn/browser": "^13.0.0",
30
- "@yackey-labs/yauth-client": "0.2.6",
31
- "@yackey-labs/yauth-shared": "0.2.6",
30
+ "@yackey-labs/yauth-client": "0.3.1",
31
+ "@yackey-labs/yauth-shared": "0.3.1",
32
32
  "solid-js": "^1.9.5"
33
33
  },
34
34
  "devDependencies": {
@@ -11,6 +11,8 @@ export const ChangePasswordForm: Component<ChangePasswordFormProps> = (
11
11
  props,
12
12
  ) => {
13
13
  const { client } = useYAuth();
14
+ const ep = client?.emailPassword;
15
+ if (!ep) return null;
14
16
  const [currentPassword, setCurrentPassword] = createSignal("");
15
17
  const [newPassword, setNewPassword] = createSignal("");
16
18
  const [confirmPassword, setConfirmPassword] = createSignal("");
@@ -39,7 +41,10 @@ export const ChangePasswordForm: Component<ChangePasswordFormProps> = (
39
41
  setLoading(true);
40
42
 
41
43
  try {
42
- await client.emailPassword.changePassword(currentPw, newPw);
44
+ await ep.changePassword({
45
+ current_password: currentPw,
46
+ new_password: newPw,
47
+ });
43
48
  setSuccess(true);
44
49
  setCurrentPassword("");
45
50
  setNewPassword("");
@@ -10,6 +10,8 @@ export const ForgotPasswordForm: Component<ForgotPasswordFormProps> = (
10
10
  props,
11
11
  ) => {
12
12
  const { client } = useYAuth();
13
+ const ep = client?.emailPassword;
14
+ if (!ep) return null;
13
15
  const [email, setEmail] = createSignal("");
14
16
  const [error, setError] = createSignal<string | null>(null);
15
17
  const [success, setSuccess] = createSignal<string | null>(null);
@@ -24,9 +26,9 @@ export const ForgotPasswordForm: Component<ForgotPasswordFormProps> = (
24
26
  try {
25
27
  const form = e.currentTarget as HTMLFormElement;
26
28
  const formData = new FormData(form);
27
- const result = await client.emailPassword.forgotPassword(
28
- (formData.get("email") as string) || email(),
29
- );
29
+ const result = await ep.forgotPassword({
30
+ email: (formData.get("email") as string) || email(),
31
+ });
30
32
  setSuccess(result.message);
31
33
  props.onSuccess?.(result.message);
32
34
  } catch (err) {
@@ -13,6 +13,8 @@ export interface LoginFormProps {
13
13
 
14
14
  export const LoginForm: Component<LoginFormProps> = (props) => {
15
15
  const { client, refetch } = useYAuth();
16
+ const ep = client?.emailPassword;
17
+ if (!ep) return null;
16
18
  const [email, setEmail] = createSignal("");
17
19
  const [password, setPassword] = createSignal("");
18
20
  const [error, setError] = createSignal<string | null>(null);
@@ -26,18 +28,14 @@ export const LoginForm: Component<LoginFormProps> = (props) => {
26
28
  try {
27
29
  const form = e.currentTarget as HTMLFormElement;
28
30
  const formData = new FormData(form);
29
- const result = await client.emailPassword.login({
31
+ await ep.login({
30
32
  email: (formData.get("email") as string) || email(),
31
33
  password: (formData.get("password") as string) || password(),
32
34
  });
33
35
 
34
- if ("mfa_required" in result && result.mfa_required) {
35
- props.onMfaRequired?.(result.pending_session_id);
36
- } else {
37
- // Session cookie is set — refetch and await so reactive store updates
38
- const user = await refetch();
39
- props.onSuccess?.(user!);
40
- }
36
+ // Session cookie is set refetch and await so reactive store updates
37
+ const user = await refetch();
38
+ props.onSuccess?.(user!);
41
39
  } catch (err) {
42
40
  const error = err instanceof Error ? err : new Error(String(err));
43
41
  setError(error.message);
@@ -8,6 +8,8 @@ export interface MagicLinkFormProps {
8
8
 
9
9
  export const MagicLinkForm: Component<MagicLinkFormProps> = (props) => {
10
10
  const { client } = useYAuth();
11
+ const ml = client?.magicLink;
12
+ if (!ml) return null;
11
13
  const [email, setEmail] = createSignal("");
12
14
  const [error, setError] = createSignal<string | null>(null);
13
15
  const [success, setSuccess] = createSignal<string | null>(null);
@@ -22,9 +24,9 @@ export const MagicLinkForm: Component<MagicLinkFormProps> = (props) => {
22
24
  try {
23
25
  const form = e.currentTarget as HTMLFormElement;
24
26
  const formData = new FormData(form);
25
- const result = await client.magicLink.send(
26
- (formData.get("email") as string) || email(),
27
- );
27
+ const result = await ml.send({
28
+ email: (formData.get("email") as string) || email(),
29
+ });
28
30
  setSuccess(result.message);
29
31
  props.onSuccess?.(result.message);
30
32
  } catch (err) {
@@ -11,6 +11,8 @@ export interface MfaChallengeProps {
11
11
 
12
12
  export const MfaChallenge: Component<MfaChallengeProps> = (props) => {
13
13
  const { client } = useYAuth();
14
+ const mfa = client?.mfa;
15
+ if (!mfa) return null;
14
16
  const [code, setCode] = createSignal("");
15
17
  const [error, setError] = createSignal<string | null>(null);
16
18
  const [loading, setLoading] = createSignal(false);
@@ -23,12 +25,12 @@ export const MfaChallenge: Component<MfaChallengeProps> = (props) => {
23
25
  try {
24
26
  const form = e.currentTarget as HTMLFormElement;
25
27
  const formData = new FormData(form);
26
- await client.mfa.verify(
27
- props.pendingSessionId,
28
- (formData.get("code") as string) || code(),
29
- );
28
+ await mfa.verify({
29
+ pending_session_id: props.pendingSessionId,
30
+ code: (formData.get("code") as string) || code(),
31
+ });
30
32
  const session = await client.getSession();
31
- props.onSuccess?.(session.user);
33
+ props.onSuccess?.(session as unknown as AuthUser);
32
34
  } catch (err) {
33
35
  const error = err instanceof Error ? err : new Error(String(err));
34
36
  setError(error.message);
@@ -10,6 +10,8 @@ type SetupStep = "begin" | "confirm" | "done";
10
10
 
11
11
  export const MfaSetup: Component<MfaSetupProps> = (props) => {
12
12
  const { client } = useYAuth();
13
+ const mfa = client?.mfa;
14
+ if (!mfa) return null;
13
15
  const [step, setStep] = createSignal<SetupStep>("begin");
14
16
  const [uri, setUri] = createSignal("");
15
17
  const [secret, setSecret] = createSignal("");
@@ -23,7 +25,7 @@ export const MfaSetup: Component<MfaSetupProps> = (props) => {
23
25
  setLoading(true);
24
26
 
25
27
  try {
26
- const result = await client.mfa.setup();
28
+ const result = await mfa.setup();
27
29
  setUri(result.otpauth_url);
28
30
  setSecret(result.secret);
29
31
  setBackupCodes(result.backup_codes);
@@ -44,7 +46,9 @@ export const MfaSetup: Component<MfaSetupProps> = (props) => {
44
46
  try {
45
47
  const form = e.currentTarget as HTMLFormElement;
46
48
  const formData = new FormData(form);
47
- await client.mfa.confirm((formData.get("code") as string) || code());
49
+ await mfa.confirm({
50
+ code: (formData.get("code") as string) || code(),
51
+ });
48
52
  setStep("done");
49
53
  props.onComplete?.(backupCodes());
50
54
  } catch (err) {
@@ -7,9 +7,11 @@ export interface OAuthButtonsProps {
7
7
 
8
8
  export const OAuthButtons: Component<OAuthButtonsProps> = (props) => {
9
9
  const { client } = useYAuth();
10
+ const oauth = client?.oauth;
11
+ if (!oauth) return null;
10
12
 
11
13
  const handleClick = (provider: string) => {
12
- client.oauth.authorize(provider);
14
+ window.location.href = oauth.authorize(provider);
13
15
  };
14
16
 
15
17
  return (
@@ -16,26 +16,34 @@ export interface PasskeyButtonProps {
16
16
 
17
17
  export const PasskeyButton: Component<PasskeyButtonProps> = (props) => {
18
18
  const { client } = useYAuth();
19
+ const pk = client?.passkey;
20
+ if (!pk) return null;
19
21
  const [error, setError] = createSignal<string | null>(null);
20
22
  const [loading, setLoading] = createSignal(false);
21
23
 
22
24
  const handleLogin = async () => {
23
- const beginResult = await client.passkey.loginBegin(
24
- props.email || undefined,
25
- );
26
- const rcr = beginResult.options as { publicKey: unknown };
25
+ const beginResult = await pk.loginBegin({
26
+ email: props.email ?? undefined,
27
+ });
28
+ const rcr = beginResult as unknown as {
29
+ options: { publicKey: unknown };
30
+ challenge_id: string;
31
+ };
27
32
  const credential = await startAuthentication({
28
- optionsJSON: rcr.publicKey as Parameters<
33
+ optionsJSON: rcr.options.publicKey as Parameters<
29
34
  typeof startAuthentication
30
35
  >[0]["optionsJSON"],
31
36
  });
32
- await client.passkey.loginFinish(beginResult.challenge_id, credential);
37
+ await pk.loginFinish({
38
+ challenge_id: rcr.challenge_id,
39
+ credential: credential as unknown as Record<string, unknown>,
40
+ });
33
41
  const session = await client.getSession();
34
- props.onSuccess?.(session.user);
42
+ props.onSuccess?.(session as unknown as AuthUser);
35
43
  };
36
44
 
37
45
  const handleRegister = async () => {
38
- const ccr = (await client.passkey.registerBegin()) as {
46
+ const ccr = (await pk.registerBegin()) as unknown as {
39
47
  publicKey: unknown;
40
48
  };
41
49
  const credential = await startRegistration({
@@ -43,7 +51,10 @@ export const PasskeyButton: Component<PasskeyButtonProps> = (props) => {
43
51
  typeof startRegistration
44
52
  >[0]["optionsJSON"],
45
53
  });
46
- await client.passkey.registerFinish(credential, "Passkey");
54
+ await pk.registerFinish({
55
+ credential: credential as unknown as Record<string, unknown>,
56
+ name: "Passkey",
57
+ });
47
58
  props.onSuccess?.(undefined as unknown as AuthUser);
48
59
  };
49
60