-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: authentication domain changes (#563)
* feat: authentication domain changes * First pass at new useLogin hook * Implements useSession * Fixes TS and linting ssues post rebase * Adds changeset * Fix unit test
- Loading branch information
1 parent
ad478bf
commit 6d0d62d
Showing
132 changed files
with
7,765 additions
and
936 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@lens-protocol/shared-kernel": patch | ||
"@lens-protocol/api-bindings": patch | ||
"@lens-protocol/domain": patch | ||
"@lens-protocol/react": patch | ||
--- | ||
|
||
**feat:** new `useLogin` and `useSession` hooks |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
import { Breadcrumbs } from './components/Breadcrumbs'; | ||
|
||
export function Layout() { | ||
return ( | ||
<> | ||
<Breadcrumbs /> | ||
<Outlet /> | ||
</> | ||
); | ||
} |
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,95 @@ | ||
import { ProfileId, useLogin, useProfiles } from '@lens-protocol/react'; | ||
import toast from 'react-hot-toast'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useAccount, useConnect } from 'wagmi'; | ||
import { InjectedConnector } from 'wagmi/connectors/injected'; | ||
|
||
import { ErrorMessage } from './components/error/ErrorMessage'; | ||
import { Loading } from './components/loading/Loading'; | ||
import { never } from './utils'; | ||
|
||
function ProfilesList({ owner }: { owner: string }) { | ||
const navigate = useNavigate(); | ||
const { execute: login, isPending: isLoginPending } = useLogin(); | ||
const { data: profiles, error, loading } = useProfiles({ where: { ownedBy: [owner] } }); | ||
|
||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const form = event.currentTarget; | ||
const formData = new FormData(form); | ||
|
||
const profileId = (formData.get('id') as string) ?? never(); | ||
|
||
const result = await login({ | ||
address: owner, | ||
profileId: profileId as ProfileId, | ||
}); | ||
|
||
if (result.isSuccess()) { | ||
toast.success(`Welcome ${String(result.value.handle)}`); | ||
return navigate('/'); | ||
} | ||
|
||
toast.error(result.error.message); | ||
}; | ||
|
||
if (loading) { | ||
return <Loading />; | ||
} | ||
|
||
if (error) { | ||
return <ErrorMessage error={error} />; | ||
} | ||
|
||
if (profiles.length === 0) { | ||
return <p>No profiles on this wallet.</p>; | ||
} | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<fieldset> | ||
<legend>Which Profile you want to log-in with?</legend> | ||
|
||
{profiles.map((profile, idx) => ( | ||
<label key={profile.id}> | ||
<input | ||
disabled={isLoginPending} | ||
type="radio" | ||
defaultChecked={idx === 0} | ||
name="id" | ||
value={profile.id} | ||
/> | ||
{profile.handle} | ||
</label> | ||
))} | ||
|
||
<div> | ||
<button disabled={isLoginPending} type="submit"> | ||
Continue | ||
</button> | ||
</div> | ||
</fieldset> | ||
</form> | ||
); | ||
} | ||
|
||
export function LogInPage() { | ||
const { address, isConnected, isConnecting } = useAccount(); | ||
|
||
const { connect } = useConnect({ | ||
connector: new InjectedConnector(), | ||
}); | ||
|
||
return ( | ||
<div> | ||
{!isConnected && ( | ||
<button disabled={isConnecting} onClick={() => connect()}> | ||
Connect first | ||
</button> | ||
)} | ||
|
||
{address && <ProfilesList owner={address} />} | ||
</div> | ||
); | ||
} |
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,6 @@ | ||
import { Link } from 'react-router-dom'; | ||
|
||
// TODO render log out button once useSession is implemented | ||
export function LoginButton() { | ||
return <Link to="/login">Log in</Link>; | ||
} |
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 @@ | ||
export * from './LoginButton'; |
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
Oops, something went wrong.