Skip to content

Commit ab921eb

Browse files
committed
updated endpoints to singular, and moved handlepasskey
1 parent 564f955 commit ab921eb

4 files changed

Lines changed: 30 additions & 26 deletions

File tree

src/AuthProvider.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface AuthContextType {
4444
updateCredential: (credential: Credential) => Promise<Credential>;
4545
deleteCredential: (credentialId: string) => Promise<void>;
4646
login: (identifier: string, passkeyAvailable: boolean) => Promise<Response>;
47-
handlePasskeyLogin: () => Promise<string>;
47+
handlePasskeyLogin: () => Promise<boolean>;
4848
}
4949

5050
export interface Credential {
@@ -131,11 +131,6 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({
131131
method: 'POST',
132132
});
133133

134-
if (!response.ok) {
135-
console.error('Something went wrong getting webauthn options');
136-
return 'Failed';
137-
}
138-
139134
const options = await response.json();
140135
const credential = await startAuthentication({ optionsJSON: options });
141136

@@ -154,22 +149,22 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({
154149
if (verificationResult.mfaLogin) {
155150
// navigate('/mfaLogin');
156151
// need to return "Success"
157-
158-
return 'Success';
152+
// can just return a bool, if success true otherwise false anywhere else
153+
return true;
159154
}
160155
await validateToken();
161156
// navigate('/');
162157
// need to return validateToken response/message
163-
return 'Token';
158+
return false;
164159
} else {
165160
console.error('Passkey login failed:', verificationResult.message);
166161
// return failed
167-
return 'Failed';
162+
return false;
168163
}
169164
} catch (error) {
170165
console.error('Passkey login error:', error);
171166
// throw error?
172-
return 'Error';
167+
return false;
173168
}
174169
};
175170

src/components/MagicLinkSent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const MagicLinkSent: React.FC = () => {
3232
const resend = async () => {
3333
if (cooldown > 0) return;
3434

35-
await fetchWithAuth(`/magic-links`, {
35+
await fetchWithAuth(`/magic-link`, {
3636
method: 'GET',
3737
headers: {
3838
'Content-Type': 'application/json',
@@ -47,7 +47,7 @@ const MagicLinkSent: React.FC = () => {
4747

4848
channel.onmessage = async event => {
4949
if (event.data?.type === 'MAGIC_LINK_AUTH_SUCCESS') {
50-
const response = await fetchWithAuth(`/magic-links/check`, {
50+
const response = await fetchWithAuth(`/magic-link/check`, {
5151
method: 'GET',
5252
headers: {
5353
'Content-Type': 'application/json',
@@ -68,7 +68,7 @@ const MagicLinkSent: React.FC = () => {
6868
useEffect(() => {
6969
const interval = setInterval(async () => {
7070
try {
71-
const response = await fetchWithAuth(`/magic-links/check`, {
71+
const response = await fetchWithAuth(`/magic-link/check`, {
7272
method: 'GET',
7373
headers: {
7474
'Content-Type': 'application/json',

src/views/Login.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const Login: React.FC = () => {
141141

142142
const sendMagicLink = async () => {
143143
try {
144-
const response = await fetchWithAuth(`/magic-links`, {
144+
const response = await fetchWithAuth(`/magic-link`, {
145145
method: 'GET',
146146
});
147147

@@ -181,8 +181,13 @@ const Login: React.FC = () => {
181181

182182
if (mode === 'login') {
183183
const res = login(identifier, passkeyAvailable);
184+
184185
if (passkeyAvailable) {
185186
console.log('herro');
187+
const passkeyResult = await handlePasskeyLogin();
188+
if (passkeyResult) {
189+
navigate('/');
190+
}
186191
} else {
187192
setShowFallbackOptions(true);
188193
console.log(setShowFallbackOptions);

src/views/VerifyMagicLink.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ const VerifyMagicLink: React.FC = () => {
2121

2222
useEffect(() => {
2323
const verify = async () => {
24-
const response = await fetchWithAuth(`/magic-links/verify/${token}`, {
25-
method: 'GET',
26-
headers: {
27-
'Content-Type': 'application/json',
28-
},
29-
});
30-
31-
if (!response.ok) {
32-
console.error('Failed to verify token');
33-
setError('Failed to verify token');
34-
return;
24+
try {
25+
const response = await fetchWithAuth(`/magic-link/verify/${token}`, {
26+
method: 'GET',
27+
headers: {
28+
'Content-Type': 'application/json',
29+
},
30+
});
31+
32+
if (!response.ok) {
33+
console.error('Failed to verify token');
34+
setError('Failed to verify token');
35+
return;
36+
}
37+
} catch (error) {
38+
console.log(error);
3539
}
3640

3741
const channel = new BroadcastChannel('seamless-auth');

0 commit comments

Comments
 (0)