-
Notifications
You must be signed in to change notification settings - Fork 20
Доработки по авторизации, легкий рефакторинг #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
57189b9
tests: fix test fault
azinit c998fe2
tests: fix act-warning
azinit 5a0f2de
refactor(auth): move router to pages level
azinit aad365d
refactor(auth): pass viewer to useAuth hook
azinit 82a88d3
fix(auth): add default redirect to home page for anon
azinit 824d8e9
fix(auth): add link to auth for sign-in button
azinit 6e8ddb9
refactor(auth): pass more credentials in localStorage
azinit deb1576
refactor(auth): fix links
azinit d27c5bd
refactor(auth): remove redundant viewer-query
azinit f0b56bf
feat(auth): add default redirect for authenticated user
azinit a90ad36
refactor(auth): links ad consts
azinit 6acecd5
tests: specify general test
azinit fddcd26
feat(meta): replace app main icon
azinit 78b9e15
chore(meta): modify meta-description
azinit 1a48d18
fix: unblur logo
azinit 2b6f7f1
fix: add FIXME
azinit 68f8288
fix: align logo with label
azinit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,7 +1,8 @@ | ||
| import React from "react"; | ||
| import { render } from "@testing-library/react"; | ||
| // import App from "."; | ||
| import App from "."; | ||
|
|
||
| test("renders without crashing", () => { | ||
| render(<div>Mock</div>); | ||
| test("renders without crashing", async () => { | ||
| const screen = render(<App />); | ||
| expect(await screen.findByTestId("gc-app")).toBeInTheDocument(); | ||
| }); |
This file contains hidden or 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 hidden or 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,4 +1,16 @@ | ||
| /** @localStorage Токен авторизации */ | ||
| export const TOKEN_KEY = "GITHUB-CLIENT__TOKEN"; | ||
| import { UserCredential } from "./types"; | ||
|
|
||
| export const getToken = () => JSON.parse(localStorage.getItem(TOKEN_KEY) || ""); | ||
| /** @localStorage Учетные данные */ | ||
| export const CREDENTIAL_KEY = "GITHUB-CLIENT__CREDENTIAL"; | ||
|
|
||
| export const getCredential = () => { | ||
| return JSON.parse(localStorage.getItem(CREDENTIAL_KEY) || "") as UserCredential; | ||
| }; | ||
|
|
||
| export const getToken = () => getCredential().accessToken; | ||
|
|
||
| export const routes = { | ||
| main: "/", | ||
| logout: "/", | ||
| login: "/auth", | ||
| }; |
This file contains hidden or 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 hidden or 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,20 +1,21 @@ | ||
| import { useLocalStorage } from "shared/hooks"; | ||
| import { TOKEN_KEY } from "./consts"; | ||
| import { CREDENTIAL_KEY } from "./consts"; | ||
| import { UserCredential } from "./types"; | ||
|
|
||
| export const useAuth = () => { | ||
| const [token, setToken] = useLocalStorage(TOKEN_KEY, ""); | ||
|
|
||
| const isAuth = !!token; | ||
| const [viewer, setViewer] = useLocalStorage<UserCredential | null>(CREDENTIAL_KEY, null); | ||
| const isAuth = !!viewer; | ||
|
|
||
| // FIXME: specify redirect urls? | ||
| const login = (token: string) => { | ||
| setToken(token); | ||
| window.location.href = "/"; | ||
| // FIXME: prohibit access? | ||
| const login = (credential: UserCredential) => { | ||
| setViewer(credential); | ||
| window.location.href = `/${credential.username}`; | ||
| }; | ||
| // FIXME: prohibit access? | ||
| const logout = () => { | ||
| setToken(""); | ||
| window.location.href = "/auth"; | ||
| setViewer(null); | ||
| }; | ||
|
|
||
| return { isAuth, token, login, logout }; | ||
| return { isAuth, viewer, login, logout }; | ||
| }; |
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,13 @@ | ||
| export type CredentialWithToken = { | ||
| credential: { | ||
| accessToken: string; | ||
| }; | ||
| }; | ||
|
|
||
| export type AuthContext = import("firebase").default.auth.UserCredential & CredentialWithToken; | ||
|
|
||
| export type UserCredential = { | ||
| accessToken: string; | ||
| username: string; | ||
| // NOTE: Возможно список хранимых полей будет расширяться позднее | ||
| }; |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.