File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Feature : Join Auth via Yandex
2+
3+ Scenario : Auth
4+ Given I am a guest user
5+ And I am on "/join" page
6+ When I click "auth-external-yandex" element
7+ Then I see "Auth with Yandex"
8+ When I click "oauth-new" element
9+ Then I see "logout-button" element
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export default function Home(): React.JSX.Element {
2121 < Link to = "/join" data-testid = "join-link" >
2222 Join
2323 </ Link >
24- < button type = "button" data-testid = "login-button" onClick = { ( ) => login ( ) } >
24+ < button type = "button" data-testid = "login-button" onClick = { ( ) => login ( { } ) } >
2525 Log In
2626 </ button >
2727 </ >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import System from '../Layout/System'
33import { Link , Navigate } from 'react-router-dom'
44import JoinForm from './JoinForm'
55import { useAuth } from '../OAuth/Provider'
6+ import AuthExternal from '../OAuth/External/AuthExternal'
67
78export default function Join ( ) : React . JSX . Element {
89 const { isAuthenticated } = useAuth ( )
@@ -15,6 +16,7 @@ export default function Join(): React.JSX.Element {
1516 < System >
1617 < h1 > Join to Us</ h1 >
1718 < JoinForm />
19+ < AuthExternal />
1820 < p >
1921 < Link to = "/" > Back to Home</ Link >
2022 </ p >
Original file line number Diff line number Diff line change 1+ .external {
2+ margin : 1rem 0 ;
3+ padding : 1rem 0 ;
4+ border-top : 1px solid # eee ;
5+ border-bottom : 1px solid # eee ;
6+ }
7+
8+ .external .heading {
9+ font-size : 0.8rem ;
10+ text-align : center;
11+ margin-bottom : 1rem ;
12+ }
13+
14+ .external .items {
15+ display : flex;
16+ flex-direction : row;
17+ justify-content : center;
18+ }
19+
20+ .external .item {
21+ margin-right : 0.5rem ;
22+ border-radius : 3px ;
23+ padding : 0.6rem 1rem ;
24+ cursor : pointer;
25+ border : 1px solid # ccc ;
26+ background : linear-gradient (to bottom, # fff, # f6f6f6 );
27+ color : # 222 ;
28+ font-size : 0.8rem ;
29+ line-height : 1 ;
30+ text-decoration : none;
31+ text-align : center;
32+ }
33+
34+ .external .item : last-of-type {
35+ margin-right : 0 ;
36+ }
37+
38+ .external .item .yandex {
39+ border : 1px solid # f60 ;
40+ background : linear-gradient (to bottom, # ff7600, # f00 );
41+ color : # fff ;
42+ }
43+
44+ .external .item .mailru {
45+ border : 1px solid # 064fcd ;
46+ background : linear-gradient (to bottom, # 256ce7, # 064fcd );
47+ color : # fff ;
48+ }
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import styles from './AuthExternal.module.css'
3+ import { useAuth } from '../Provider'
4+
5+ export default function AuthExternal ( ) : React . JSX . Element {
6+ const { login } = useAuth ( )
7+
8+ return (
9+ < div className = { styles . external } >
10+ < div className = { styles . heading } > Or log in via:</ div >
11+ < div className = { styles . items } data-testid = "auth-external" >
12+ < div
13+ className = { styles . item + ' ' + styles . yandex }
14+ onClick = { ( ) => login ( { provider : 'yandex' } ) }
15+ data-testid = "auth-external-yandex"
16+ >
17+ Yandex
18+ </ div >
19+ < div
20+ className = { styles . item + ' ' + styles . mailru }
21+ onClick = { ( ) => login ( { provider : 'mailru' } ) }
22+ data-testid = "auth-external-mailru"
23+ >
24+ MailRu
25+ </ div >
26+ </ div >
27+ </ div >
28+ )
29+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { createContext } from 'react'
33export type AuthContextValue = {
44 isAuthenticated : boolean
55 getToken ( ) : Promise < string >
6- login ( ) : void
6+ login ( extra : Record < string , string > ) : void
77 logout ( ) : void
88 loading : boolean
99 error : string | null
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ export default function AuthProvider({
154154 return ( ) => window . removeEventListener ( 'storage' , listener )
155155 } , [ ] )
156156
157- const login = useCallback ( async ( ) => {
157+ const login = useCallback ( async ( extra : Record < string , string > ) => {
158158 const currentLocation = window . location . pathname
159159 const codeVerifier = generateCodeVerifier ( )
160160 const codeChallenge = await generateCodeChallenge ( codeVerifier )
@@ -172,6 +172,7 @@ export default function AuthProvider({
172172 redirect_uri : window . location . origin + redirectPath ,
173173 scope,
174174 state,
175+ ...extra ,
175176 } )
176177
177178 window . location . assign ( authorizeUrl + '?' + args )
You can’t perform that action at this time.
0 commit comments