-
Notifications
You must be signed in to change notification settings - Fork 0
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 #8 from Selleo/jw/auth-screens
feat: auth screens
- Loading branch information
Showing
45 changed files
with
2,638 additions
and
328 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
DATABASE_URL="postgres://postgres:guidebook@localhost:5432/guidebook" | ||
JWT_SECRET= | ||
JWT_REFRESH_SECRET= | ||
CORS_ORIGIN= |
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
4 changes: 2 additions & 2 deletions
4
examples/common_nestjs_remix/apps/api/src/utils/save-swagger-to-file.ts
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 |
---|---|---|
|
@@ -48,6 +48,9 @@ module.exports = { | |
typescript: {}, | ||
}, | ||
}, | ||
rules: { | ||
"react/prop-types": "off", | ||
}, | ||
}, | ||
|
||
// Typescript | ||
|
27 changes: 26 additions & 1 deletion
27
examples/common_nestjs_remix/apps/web/app/api/api-client.ts
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,6 +1,31 @@ | ||
import { useAuthStore } from "~/modules/Auth/authStore"; | ||
import { API } from "./generated-api"; | ||
|
||
export const ApiClient = new API({ | ||
baseURL: import.meta.env.API_URL, | ||
baseURL: import.meta.env.VITE_API_URL, | ||
secure: true, | ||
withCredentials: true, | ||
}); | ||
|
||
ApiClient.instance.interceptors.response.use( | ||
(response) => response, | ||
async (error) => { | ||
const isLoggedIn = useAuthStore.getState().isLoggedIn; | ||
const originalRequest = error.config; | ||
|
||
if (error.response?.status === 401 && !originalRequest._retry) { | ||
originalRequest._retry = true; | ||
if (!isLoggedIn) return; | ||
|
||
try { | ||
await ApiClient.auth.authControllerRefreshTokens(); | ||
|
||
return ApiClient.instance(originalRequest); | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
} | ||
|
||
return Promise.reject(error); | ||
} | ||
); |
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
21 changes: 0 additions & 21 deletions
21
examples/common_nestjs_remix/apps/web/app/api/mutations/useCreateProperty.ts
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
examples/common_nestjs_remix/apps/web/app/api/mutations/useLoginUser.ts
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,30 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { ApiClient } from "../api-client"; | ||
import { LoginBody } from "../generated-api"; | ||
import { useAuthStore } from "~/modules/Auth/authStore"; | ||
import { toast } from "sonner"; | ||
import { AxiosError } from "axios"; | ||
|
||
type LoginUserOptions = { | ||
data: LoginBody; | ||
}; | ||
|
||
export function useLoginUser() { | ||
const { setLoggedIn } = useAuthStore(); | ||
return useMutation({ | ||
mutationFn: async (options: LoginUserOptions) => { | ||
const response = await ApiClient.auth.authControllerLogin(options.data); | ||
|
||
return response.data; | ||
}, | ||
onSuccess: () => { | ||
setLoggedIn(true); | ||
}, | ||
onError: (error) => { | ||
if (error instanceof AxiosError) { | ||
return toast.error(error.response?.data.message); | ||
} | ||
toast.error(error.message); | ||
}, | ||
}); | ||
} |
25 changes: 25 additions & 0 deletions
25
examples/common_nestjs_remix/apps/web/app/api/mutations/useLogoutUser.ts
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,25 @@ | ||
import { useAuthStore } from "./../../modules/Auth/authStore"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { ApiClient } from "../api-client"; | ||
import { toast } from "sonner"; | ||
import { AxiosError } from "axios"; | ||
|
||
export function useLogoutUser() { | ||
const { setLoggedIn } = useAuthStore(); | ||
return useMutation({ | ||
mutationFn: async () => { | ||
const response = await ApiClient.auth.authControllerLogout(); | ||
|
||
return response.data; | ||
}, | ||
onSuccess: () => { | ||
setLoggedIn(false); | ||
}, | ||
onError: (error) => { | ||
if (error instanceof AxiosError) { | ||
return toast.error(error.response?.data.message); | ||
} | ||
toast.error(error.message); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.