mirror of
https://github.com/wassname/talk.git
synced 2026-07-26 13:37:38 +08:00
* feat: Implement new Sign In view * feat: Move forgot + resetPassword to new design * feat: Implement sign up with new design * fix: narrow gutter * test: add unit tests * test: integration tests * feat: support show / hide password * feat: support oauth2 flow * feat: add views for user completion * feat: implement oauth2 sign up * test: fix snapshots * fix: lint * fix: get more complete mutation response * fix: removed array of OIDC integrations * fix: renamed resolver function * fix: adapt oidc client implementation * fix: targetFilter should be stream on signup * fix: removed unneeded message * fix: moved password into local profile * fix: made username optional, removed valid null value * fix: linting * fix: respect targetFilter * feat: support user registration mutations - Added `setUsername` - Added `setEmail` - Added `setPassword` - Added `permit` to `@auth` - Added `email` to `User` * fix: fixed issue with query * feat: added user password update * feat: complete sign in mutation * fix: adapt some rebasing gitches * test: improve tests * test: unittest for setting auth token * fix: failing tests * test: move most tests from enzyme to react-test-renderer * fix: remove schema warnings in tests * test: improve window mock * test: test different social login configurations * test: test social logins for sign up * fix: use htmlFor instead of for * test: more feature tests * feat: always go through account completion * test: feature test account completion * feat: addtional account completion test * Update start.ts * chore: refactor auth token retrieval logic
176 lines
4.9 KiB
TypeScript
176 lines
4.9 KiB
TypeScript
import * as React from "react";
|
|
import { Component } from "react";
|
|
|
|
import {
|
|
graphql,
|
|
withFragmentContainer,
|
|
withLocalStateContainer,
|
|
} from "talk-framework/lib/relay";
|
|
import { SignOutMutation, withSignOutMutation } from "talk-framework/mutations";
|
|
import { UserBoxContainer_me as MeData } from "talk-stream/__generated__/UserBoxContainer_me.graphql";
|
|
import { UserBoxContainer_settings as SettingsData } from "talk-stream/__generated__/UserBoxContainer_settings.graphql";
|
|
import { UserBoxContainerLocal as Local } from "talk-stream/__generated__/UserBoxContainerLocal.graphql";
|
|
import UserBoxUnauthenticated from "talk-stream/components/UserBoxUnauthenticated";
|
|
import {
|
|
SetAuthPopupStateMutation,
|
|
ShowAuthPopupMutation,
|
|
withSetAuthPopupStateMutation,
|
|
withShowAuthPopupMutation,
|
|
} from "talk-stream/mutations";
|
|
import { Popup } from "talk-ui/components";
|
|
|
|
import { urls } from "talk-framework/helpers";
|
|
import UserBoxAuthenticated from "../components/UserBoxAuthenticated";
|
|
|
|
interface InnerProps {
|
|
local: Local;
|
|
me: MeData | null;
|
|
settings: SettingsData;
|
|
showAuthPopup: ShowAuthPopupMutation;
|
|
setAuthPopupState: SetAuthPopupStateMutation;
|
|
signOut: SignOutMutation;
|
|
}
|
|
|
|
export class UserBoxContainer extends Component<InnerProps> {
|
|
private handleFocus = () => this.props.setAuthPopupState({ focus: true });
|
|
private handleBlur = () => this.props.setAuthPopupState({ focus: false });
|
|
private handleClose = () => this.props.setAuthPopupState({ open: false });
|
|
private handleSignIn = () => this.props.showAuthPopup({ view: "SIGN_IN" });
|
|
private handleRegister = () => this.props.showAuthPopup({ view: "SIGN_UP" });
|
|
private handleSignOut = () => this.props.signOut();
|
|
|
|
private get supportsLogout() {
|
|
return !!this.props.local.authJTI;
|
|
}
|
|
|
|
private get supportsRegister() {
|
|
const integrations = this.props.settings.auth.integrations;
|
|
return [
|
|
integrations.facebook,
|
|
integrations.google,
|
|
integrations.local,
|
|
integrations.oidc,
|
|
].some(i => i.allowRegistration && i.enabled && i.targetFilter.stream);
|
|
}
|
|
|
|
private get weControlAuth() {
|
|
const integrations = this.props.settings.auth.integrations;
|
|
return [
|
|
integrations.facebook,
|
|
integrations.google,
|
|
integrations.local,
|
|
integrations.oidc,
|
|
].some(i => i.enabled && i.targetFilter.stream);
|
|
}
|
|
|
|
public render() {
|
|
const {
|
|
local: {
|
|
authPopup: { open, focus, view },
|
|
},
|
|
me,
|
|
} = this.props;
|
|
|
|
if (me) {
|
|
return (
|
|
<UserBoxAuthenticated
|
|
onSignOut={this.handleSignOut}
|
|
username={me.username!}
|
|
showLogoutButton={this.supportsLogout}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (!this.weControlAuth) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Popup
|
|
href={`${urls.embed.auth}?view=${view}`}
|
|
title="Talk Auth"
|
|
features="menubar=0,resizable=0,width=350,height=450,top=100,left=500"
|
|
open={open}
|
|
focus={focus}
|
|
onFocus={this.handleFocus}
|
|
onBlur={this.handleBlur}
|
|
onClose={this.handleClose}
|
|
/>
|
|
<UserBoxUnauthenticated
|
|
onSignIn={this.handleSignIn}
|
|
onRegister={
|
|
(this.supportsRegister && this.handleRegister) || undefined
|
|
}
|
|
showRegisterButton={this.supportsRegister}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
const enhanced = withSignOutMutation(
|
|
withSetAuthPopupStateMutation(
|
|
withShowAuthPopupMutation(
|
|
withLocalStateContainer(
|
|
graphql`
|
|
fragment UserBoxContainerLocal on Local {
|
|
authPopup {
|
|
open
|
|
focus
|
|
view
|
|
}
|
|
authJTI
|
|
}
|
|
`
|
|
)(
|
|
withFragmentContainer<InnerProps>({
|
|
me: graphql`
|
|
fragment UserBoxContainer_me on User {
|
|
username
|
|
}
|
|
`,
|
|
settings: graphql`
|
|
fragment UserBoxContainer_settings on Settings {
|
|
auth {
|
|
integrations {
|
|
local {
|
|
enabled
|
|
allowRegistration
|
|
targetFilter {
|
|
stream
|
|
}
|
|
}
|
|
oidc {
|
|
enabled
|
|
allowRegistration
|
|
targetFilter {
|
|
stream
|
|
}
|
|
}
|
|
google {
|
|
enabled
|
|
allowRegistration
|
|
targetFilter {
|
|
stream
|
|
}
|
|
}
|
|
facebook {
|
|
enabled
|
|
allowRegistration
|
|
targetFilter {
|
|
stream
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
})(UserBoxContainer)
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
export default enhanced;
|