-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add static login link for sandbox setup (#168)
- Loading branch information
1 parent
93fb6af
commit 2074050
Showing
12 changed files
with
152 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Box, Text } from 'grommet' | ||
import { useEffect } from 'react' | ||
import { useMutation } from 'react-apollo' | ||
import { useParams } from 'react-router' | ||
|
||
import { setToken } from '../helpers/auth' | ||
|
||
import { LOGIN_LINK } from './graphql/users' | ||
import { LoginPortal } from './Login' | ||
import { LoopingLogo } from './utils/AnimatedLogo' | ||
|
||
export function LinkLogin() { | ||
const { key } = useParams() | ||
const [mutation, { error }] = useMutation(LOGIN_LINK, { | ||
variables: { key }, | ||
onCompleted: ({ loginLink: { jwt } }) => { | ||
setToken(jwt) | ||
window.location = '/' | ||
}, | ||
onError: console.log, | ||
}) | ||
|
||
useEffect(() => { | ||
mutation() | ||
}, []) | ||
|
||
if (error) { | ||
return ( | ||
<Box | ||
fill | ||
align="center" | ||
justify="center" | ||
> | ||
<Box> | ||
<Text>This login link is invalid</Text> | ||
</Box> | ||
</Box> | ||
) | ||
} | ||
|
||
return ( | ||
<LoginPortal> | ||
<LoopingLogo /> | ||
</LoginPortal> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -30,6 +30,10 @@ config :console, | |
git_ssh_key: :pass, | ||
grafana_dns: "grafana.example.com" | ||
|
||
config :console, :login_link, | ||
key: "test-key", | ||
email: "[email protected]" | ||
|
||
config :console, :consumers, [Console.EchoConsumer] | ||
|
||
config :kazan, :server, %{url: "kubernetes.default", auth: %{token: "your_token"}} |
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
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 |
---|---|---|
|
@@ -22,6 +22,45 @@ defmodule Console.GraphQl.UserMutationsTest do | |
end | ||
end | ||
|
||
describe "loginLink" do | ||
test "A user can be signed in via a random link" do | ||
{:ok, user} = Users.create_user(%{ | ||
name: "some user", | ||
email: "[email protected]", | ||
password: "bogus password" | ||
}) | ||
|
||
{:ok, %{data: %{"loginLink" => signin}}} = run_query(""" | ||
mutation Link($key: String!) { | ||
loginLink(key: $key) { | ||
id | ||
jwt | ||
} | ||
} | ||
""", %{"key" => "test-key"}) | ||
|
||
assert signin["id"] == user.id | ||
assert signin["jwt"] | ||
end | ||
|
||
test "If links are invalid signin won't work" do | ||
{:ok, _} = Users.create_user(%{ | ||
name: "some user", | ||
email: "[email protected]", | ||
password: "bogus password" | ||
}) | ||
|
||
{:ok, %{data: %{"loginLink" => nil}, errors: [_ | _]}} = run_query(""" | ||
mutation Link($key: String!) { | ||
loginLink(key: $key) { | ||
id | ||
jwt | ||
} | ||
} | ||
""", %{"key" => "invalid"}) | ||
end | ||
end | ||
|
||
describe "updateUser" do | ||
test "It can update a user's attributes" do | ||
{:ok, user} = Users.create_user(%{ | ||
|