@micha.bigler/ui-core-micha 1.2.0 → 1.2.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.
@@ -1,9 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  // src/auth/components/LoginForm.jsx
3
3
  import React, { useState } from 'react';
4
4
  import { Box, TextField, Button, Typography, Divider, } from '@mui/material';
5
5
  import SocialLoginButtons from './SocialLoginButtons';
6
- const LoginForm = ({ onSubmit, onForgotPassword, onSocialLogin, onSignUp, // <--- NEU
6
+ const LoginForm = ({ onSubmit, onForgotPassword, onSocialLogin, onPasskeyLogin, onSignUp, // <--- NEU
7
7
  error, disabled = false, }) => {
8
8
  const [identifier, setIdentifier] = useState('');
9
9
  const [password, setPassword] = useState('');
@@ -19,6 +19,6 @@ error, disabled = false, }) => {
19
19
  alignItems: 'center',
20
20
  mt: 1,
21
21
  gap: 1,
22
- }, children: [_jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx(Button, { type: "submit", variant: "contained", disabled: disabled, children: "Login" }), onSignUp && (_jsx(Button, { type: "button", variant: "outlined", onClick: onSignUp, disabled: disabled, children: "Sign up" }))] }), _jsx(Button, { type: "button", variant: "outlined", onClick: onForgotPassword, disabled: disabled, children: "Forgot password?" })] }), _jsx(Divider, { sx: { my: 2 }, children: "or" }), _jsx(SocialLoginButtons, { onProviderClick: onSocialLogin }), _jsx(Divider, { sx: { my: 2 }, children: "or" }), _jsx(Box, { sx: { mt: 2, textAlign: 'center' }, children: _jsx(Button, { variant: "text", onClick: handlePasskeyLogin, disabled: submitting || !window.PublicKeyCredential, children: "Use passkey" }) })] }));
22
+ }, children: [_jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx(Button, { type: "submit", variant: "contained", disabled: disabled, children: "Login" }), onSignUp && (_jsx(Button, { type: "button", variant: "outlined", onClick: onSignUp, disabled: disabled, children: "Sign up" }))] }), _jsx(Button, { type: "button", variant: "outlined", onClick: onForgotPassword, disabled: disabled, children: "Forgot password?" })] }), _jsx(Divider, { sx: { my: 2 }, children: "or" }), _jsx(SocialLoginButtons, { onProviderClick: onSocialLogin }), onPasskeyLogin && (_jsxs(_Fragment, { children: [_jsx(Divider, { sx: { my: 2 }, children: "or" }), _jsx(Box, { sx: { mt: 2, textAlign: 'center' }, children: _jsx(Button, { variant: "text", type: "button", onClick: onPasskeyLogin, disabled: disabled || !window.PublicKeyCredential, children: "Use passkey" }) })] }))] }));
23
23
  };
24
24
  export default LoginForm;
@@ -45,9 +45,27 @@ export function LoginPage() {
45
45
  setError('Could not start social login.');
46
46
  }
47
47
  };
48
+ const handlePasskeyLogin = async () => {
49
+ var _a, _b;
50
+ setError('');
51
+ setSubmitting(true);
52
+ try {
53
+ const { user } = await authApi.loginWithPasskey(); // API muss natürlich implementiert sein
54
+ login(user);
55
+ navigate('/');
56
+ }
57
+ catch (err) {
58
+ setError(((_b = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.detail) ||
59
+ (err === null || err === void 0 ? void 0 : err.message) ||
60
+ 'Passkey login failed.');
61
+ }
62
+ finally {
63
+ setSubmitting(false);
64
+ }
65
+ };
48
66
  const handleSignUp = () => {
49
67
  navigate('/signup');
50
68
  };
51
- return (_jsxs(NarrowPage, { title: "Login", children: [_jsx(Helmet, { children: _jsx("title", { children: "PROJECT_NAME \u2013 Login" }) }), error && (_jsx(Typography, { color: "error", gutterBottom: true, children: error })), _jsx(LoginForm, { onSubmit: handleSubmit, onForgotPassword: handleForgotPassword, onSocialLogin: handleSocialLogin, onSignUp: handleSignUp, error: undefined, disabled: submitting })] }));
69
+ return (_jsxs(NarrowPage, { title: "Login", children: [_jsx(Helmet, { children: _jsx("title", { children: "PROJECT_NAME \u2013 Login" }) }), error && (_jsx(Typography, { color: "error", gutterBottom: true, children: error })), _jsx(LoginForm, { onSubmit: handleSubmit, onForgotPassword: handleForgotPassword, onSocialLogin: handleSocialLogin, onPasskeyLogin: handlePasskeyLogin, onSignUp: handleSignUp, error: undefined, disabled: submitting })] }));
52
70
  }
53
71
  export default LoginPage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "private": false,
@@ -13,6 +13,7 @@ const LoginForm = ({
13
13
  onSubmit,
14
14
  onForgotPassword,
15
15
  onSocialLogin,
16
+ onPasskeyLogin,
16
17
  onSignUp, // <--- NEU
17
18
  error,
18
19
  disabled = false,
@@ -102,17 +103,22 @@ const LoginForm = ({
102
103
 
103
104
  <SocialLoginButtons onProviderClick={onSocialLogin} />
104
105
 
105
- <Divider sx={{ my: 2 }}>or</Divider>
106
+ {onPasskeyLogin && (
107
+ <>
108
+ <Divider sx={{ my: 2 }}>or</Divider>
106
109
 
107
- <Box sx={{ mt: 2, textAlign: 'center' }}>
108
- <Button
109
- variant="text"
110
- onClick={handlePasskeyLogin}
111
- disabled={submitting || !window.PublicKeyCredential}
112
- >
113
- Use passkey
114
- </Button>
115
- </Box>
110
+ <Box sx={{ mt: 2, textAlign: 'center' }}>
111
+ <Button
112
+ variant="text"
113
+ type="button"
114
+ onClick={onPasskeyLogin}
115
+ disabled={disabled || !window.PublicKeyCredential}
116
+ >
117
+ Use passkey
118
+ </Button>
119
+ </Box>
120
+ </>
121
+ )}
116
122
  </Box>
117
123
  );
118
124
  };
@@ -47,6 +47,24 @@ export function LoginPage() {
47
47
  }
48
48
  };
49
49
 
50
+ const handlePasskeyLogin = async () => {
51
+ setError('');
52
+ setSubmitting(true);
53
+ try {
54
+ const { user } = await authApi.loginWithPasskey(); // API muss natürlich implementiert sein
55
+ login(user);
56
+ navigate('/');
57
+ } catch (err) {
58
+ setError(
59
+ err?.response?.data?.detail ||
60
+ err?.message ||
61
+ 'Passkey login failed.',
62
+ );
63
+ } finally {
64
+ setSubmitting(false);
65
+ }
66
+ };
67
+
50
68
  const handleSignUp = () => {
51
69
  navigate('/signup');
52
70
  };
@@ -67,6 +85,7 @@ export function LoginPage() {
67
85
  onSubmit={handleSubmit}
68
86
  onForgotPassword={handleForgotPassword}
69
87
  onSocialLogin={handleSocialLogin}
88
+ onPasskeyLogin={handlePasskeyLogin}
70
89
  onSignUp={handleSignUp}
71
90
  error={undefined}
72
91
  disabled={submitting}