This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
forked from YuraNick/Praga
-
Notifications
You must be signed in to change notification settings - Fork 3
Добавила OAuth авторизацию #13
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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,5 @@ | ||
import icon from '@assets/RU.svg' | ||
export const YandexIcon = () => { | ||
return <img src={icon}/> | ||
|
||
} |
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,23 @@ | ||
import { oauthYandex, fetchUser } from '@store/actions/AuthActionCreators' | ||
import { useAppDispatch } from '@store/index' | ||
import { OauthData } from '@store/types' | ||
|
||
export const useOAuth = () => { | ||
const REDIRECT_URI = 'http://localhost:3000' | ||
const dispatch = useAppDispatch() | ||
const url = document.location.href | ||
const code = url.split('=').pop(); | ||
return () => { | ||
if (/code/.test(url)) { | ||
dispatch(oauthYandex({ | ||
code: code, | ||
redirect_uri: REDIRECT_URI | ||
} as OauthData)) | ||
.then(res => { | ||
if (res.payload === 'OK') { | ||
dispatch(fetchUser()) | ||
} | ||
}) | ||
} | ||
} | ||
} |
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,16 @@ | ||
import { getServiceId } from "@store/actions/AuthActionCreators" | ||
import { useAppDispatch } from "@store/index" | ||
|
||
export const useServiceId = () => { | ||
const dispatch = useAppDispatch() | ||
const REDIRECT_URI = 'http://localhost:3000'; | ||
|
||
return () => { | ||
dispatch(getServiceId()) | ||
.then(res => { | ||
if (res.payload.service_id) { | ||
document.location = `https://oauth.yandex.ru/authorize?response_type=code&client_id=${res.payload.service_id}&redirect_uri=${REDIRECT_URI}` | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { Box, Container, Button, Typography } from '@mui/material' | ||
import { fetchUser } from '@store/actions/AuthActionCreators' | ||
import { useAppDispatch } from '@store/index' | ||
import { useOAuth } from '../../hooks/useOAuth' | ||
import { useEffect } from 'react' | ||
import { useAuth } from '../../hooks/useAuth' | ||
import styles from './styles' | ||
|
||
export default function Intro() { | ||
const isOAuth = useOAuth() | ||
const isAuth = useAuth() | ||
const dispatch = useAppDispatch() | ||
|
||
useEffect(() => { | ||
isOAuth() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: функции обычно именуют с глагола, а There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Поправила |
||
dispatch(fetchUser()) | ||
}, []) | ||
const isAuth = useAuth() | ||
const handleClick = () => { | ||
isAuth() | ||
} | ||
|
||
return ( | ||
<Box sx={{ ...styles.page }}> | ||
|
@@ -29,7 +30,7 @@ export default function Intro() { | |
alignItems: 'flex-start', | ||
}}> | ||
<Button | ||
onClick={handleClick} | ||
onClick={() => isAuth()} | ||
sx={{ marginBottom: '1rem' }} | ||
variant="contained" | ||
size="large" | ||
|
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
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,7 +1,6 @@ | ||
const CACHE_NAME = 'my-site-cache-v1' | ||
|
||
const URLS = [ | ||
// '/', | ||
'./src/main.tsx', | ||
] | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В 9м спринте понадобится подставлять продовый или дев-адрес в зависимости от окружения. Это будет сложно сделать, если константа дублируюется в нескольких местах
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Когда настроим докер контейнер и впишем авторизацию в серверный рендеринг - поправлю этот момент
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В целом можно было бы сразу вынести общую константу, но не настаиваю