-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from supertokens/areeb/error-boundary-and-misc
feat: Add email password login to the dashboard
- Loading branch information
Showing
50 changed files
with
1,358 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { StorageKeys } from "../constants"; | ||
import { localStorageHandler } from "../services/storage"; | ||
import { getApiUrl, useFetchData } from "../utils"; | ||
|
||
const useAuthService = () => { | ||
const fetchData = useFetchData(); | ||
|
||
const logout = async () => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/signout"), | ||
method: "POST", | ||
}); | ||
const body = await response.json(); | ||
if (body.status === "OK") { | ||
localStorageHandler.removeItem(StorageKeys.AUTH_KEY); | ||
window.location.reload(); | ||
} | ||
}; | ||
|
||
const signIn = async ({ email, password }: { email: string; password: string }) => { | ||
return await fetchData({ | ||
url: getApiUrl("/api/signin"), | ||
method: "POST", | ||
config: { | ||
body: JSON.stringify({ | ||
email, | ||
password, | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
return { | ||
logout, | ||
signIn, | ||
}; | ||
}; | ||
|
||
export default useAuthService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
import { fetchDataAndRedirectIf401, getApiUrl } from "../../utils"; | ||
|
||
export const deleteUser = async (userId: string): Promise<{ status: "OK" } | undefined> => { | ||
const response = await fetchDataAndRedirectIf401({ | ||
url: getApiUrl("/api/user"), | ||
method: "DELETE", | ||
query: { | ||
userId, | ||
}, | ||
}); | ||
|
||
if (response.ok) { | ||
const body = await response.json(); | ||
|
||
if (body.status !== "OK") { | ||
return undefined; | ||
import { getApiUrl, useFetchData } from "../../utils"; | ||
|
||
type TDeleteUserResponse = Promise<{ status: "OK" } | undefined>; | ||
|
||
interface IUseDeleteUserService { | ||
deleteUser: (userId: string) => TDeleteUserResponse; | ||
} | ||
|
||
const useDeleteUserService = (): IUseDeleteUserService => { | ||
const fetchData = useFetchData(); | ||
|
||
const deleteUser = async (userId: string): Promise<{ status: "OK" } | undefined> => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/user"), | ||
method: "DELETE", | ||
query: { | ||
userId, | ||
}, | ||
}); | ||
|
||
if (response.ok) { | ||
const body = await response.json(); | ||
|
||
if (body.status !== "OK") { | ||
return undefined; | ||
} | ||
|
||
return body; | ||
} | ||
|
||
return body; | ||
} | ||
return undefined; | ||
}; | ||
|
||
return undefined; | ||
return { | ||
deleteUser, | ||
}; | ||
}; | ||
|
||
export default useDeleteUserService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
import { EmailVerificationStatus } from "../../../../ui/pages/usersList/types"; | ||
import { fetchDataAndRedirectIf401, getApiUrl } from "../../../../utils"; | ||
import { getApiUrl, useFetchData } from "../../../../utils"; | ||
|
||
export const getUserEmailVerificationStatus = async (userId: string): Promise<EmailVerificationStatus> => { | ||
const response = await fetchDataAndRedirectIf401({ | ||
url: getApiUrl("/api/user/email/verify"), | ||
method: "GET", | ||
query: { userId }, | ||
}); | ||
interface IUseVerifyUserEmailService { | ||
getUserEmailVerificationStatus: (userId: string) => Promise<EmailVerificationStatus>; | ||
updateUserEmailVerificationStatus: (userId: string, isEmailVerified: boolean) => Promise<boolean>; | ||
} | ||
|
||
const body = await response.json(); | ||
return body; | ||
}; | ||
const useVerifyUserEmail = (): IUseVerifyUserEmailService => { | ||
const fetchData = useFetchData(); | ||
|
||
const getUserEmailVerificationStatus = async (userId: string): Promise<EmailVerificationStatus> => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/user/email/verify"), | ||
method: "GET", | ||
query: { userId }, | ||
}); | ||
|
||
const body = await response.json(); | ||
return body; | ||
}; | ||
|
||
export const updateUserEmailVerificationStatus = async (userId: string, isEmailVerified: boolean) => { | ||
const response = await fetchDataAndRedirectIf401({ | ||
url: getApiUrl("/api/user/email/verify"), | ||
method: "PUT", | ||
config: { | ||
body: JSON.stringify({ verified: isEmailVerified, userId }), | ||
}, | ||
}); | ||
return response?.ok; | ||
const updateUserEmailVerificationStatus = async (userId: string, isEmailVerified: boolean) => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/user/email/verify"), | ||
method: "PUT", | ||
config: { | ||
body: JSON.stringify({ verified: isEmailVerified, userId }), | ||
}, | ||
}); | ||
return response?.ok; | ||
}; | ||
|
||
return { | ||
getUserEmailVerificationStatus, | ||
updateUserEmailVerificationStatus, | ||
}; | ||
}; | ||
|
||
export default useVerifyUserEmail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import { fetchDataAndRedirectIf401, getApiUrl } from "../../../../utils"; | ||
|
||
export const sendUserEmailVerification = async (userId: string) => { | ||
const response = await fetchDataAndRedirectIf401({ | ||
url: getApiUrl("/api/user/email/verify/token"), | ||
method: "POST", | ||
config: { | ||
body: JSON.stringify({ | ||
userId, | ||
}), | ||
}, | ||
}); | ||
return response?.ok; | ||
import { getApiUrl, useFetchData } from "../../../../utils"; | ||
|
||
interface IUseVerifyUserTokenService { | ||
sendUserEmailVerification: (userId: string) => Promise<boolean>; | ||
} | ||
|
||
const useVerifyUserTokenService = (): IUseVerifyUserTokenService => { | ||
const fetchData = useFetchData(); | ||
|
||
const sendUserEmailVerification = async (userId: string) => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/user/email/verify/token"), | ||
method: "POST", | ||
config: { | ||
body: JSON.stringify({ | ||
userId, | ||
}), | ||
}, | ||
}); | ||
return response?.ok; | ||
}; | ||
|
||
return { sendUserEmailVerification }; | ||
}; | ||
|
||
export default useVerifyUserTokenService; |
Oops, something went wrong.