mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
[next] UserBox with respect to auth settings (#2079)
* feat: adapt userbox according to settings in embed stream * fix: lint and test * feat: respect allowRegistration
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
} 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 {
|
||||
@@ -24,6 +25,7 @@ import UserBoxAuthenticated from "../components/UserBoxAuthenticated";
|
||||
interface InnerProps {
|
||||
local: Local;
|
||||
me: MeData | null;
|
||||
settings: SettingsData;
|
||||
showAuthPopup: ShowAuthPopupMutation;
|
||||
setAuthPopupState: SetAuthPopupStateMutation;
|
||||
signOut: SignOutMutation;
|
||||
@@ -37,6 +39,31 @@ export class UserBoxContainer extends Component<InnerProps> {
|
||||
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.allowRegistration &&
|
||||
integrations.facebook.enabled) ||
|
||||
(integrations.google.allowRegistration && integrations.google.enabled) ||
|
||||
(integrations.local.allowRegistration && integrations.local.enabled) ||
|
||||
integrations.oidc.some(c => c.allowRegistration && c.enabled)
|
||||
);
|
||||
}
|
||||
|
||||
private get weControlAuth() {
|
||||
const integrations = this.props.settings.auth.integrations;
|
||||
return (
|
||||
integrations.facebook.enabled ||
|
||||
integrations.google.enabled ||
|
||||
integrations.local.enabled ||
|
||||
integrations.oidc.some(c => c.enabled)
|
||||
);
|
||||
}
|
||||
|
||||
public render() {
|
||||
const {
|
||||
local: {
|
||||
@@ -48,13 +75,17 @@ export class UserBoxContainer extends Component<InnerProps> {
|
||||
if (me) {
|
||||
return (
|
||||
<UserBoxAuthenticated
|
||||
onSignOut={this.handleSignOut}
|
||||
// TODO: why nullable?
|
||||
onSignOut={(this.weControlAuth && this.handleSignOut) || undefined}
|
||||
username={me.username!}
|
||||
showLogoutButton={this.supportsLogout}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.weControlAuth) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Popup
|
||||
@@ -69,7 +100,10 @@ export class UserBoxContainer extends Component<InnerProps> {
|
||||
/>
|
||||
<UserBoxUnauthenticated
|
||||
onSignIn={this.handleSignIn}
|
||||
onRegister={this.handleRegister}
|
||||
onRegister={
|
||||
(this.supportsRegister && this.handleRegister) || undefined
|
||||
}
|
||||
showRegisterButton={this.supportsRegister}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
@@ -87,6 +121,7 @@ const enhanced = withSignOutMutation(
|
||||
focus
|
||||
view
|
||||
}
|
||||
authJTI
|
||||
}
|
||||
`
|
||||
)(
|
||||
@@ -96,6 +131,34 @@ const enhanced = withSignOutMutation(
|
||||
username
|
||||
}
|
||||
`,
|
||||
settings: graphql`
|
||||
fragment UserBoxContainer_settings on Settings {
|
||||
auth {
|
||||
integrations {
|
||||
local {
|
||||
enabled
|
||||
allowRegistration
|
||||
}
|
||||
sso {
|
||||
enabled
|
||||
allowRegistration
|
||||
}
|
||||
oidc {
|
||||
enabled
|
||||
allowRegistration
|
||||
}
|
||||
google {
|
||||
enabled
|
||||
allowRegistration
|
||||
}
|
||||
facebook {
|
||||
enabled
|
||||
allowRegistration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
})(UserBoxContainer)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user