1
/*
2
 * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
 * the License. A copy of the License is located at
6
 *
7
 *     http://aws.amazon.com/apache2.0/
8
 *
9
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
 * and limitations under the License.
12
 */
13

14 1
import * as React from 'react';
15

16 1
import { I18n } from '@aws-amplify/core';
17 1
import { Auth } from '@aws-amplify/auth';
18 1
import AmplifyTheme from '../../Amplify-UI/Amplify-UI-Theme';
19 1
import { oAuthSignInButton } from '@aws-amplify/ui';
20 1
import {
21
	SignInButton,
22
	SignInButtonContent,
23
} from '../../Amplify-UI/Amplify-UI-Components-React';
24

25 1
export function withOAuth(Comp) {
26 1
	return class extends React.Component<any, any> {
27
		constructor(props: any) {
28 1
			super(props);
29 1
			this.signIn = this.signIn.bind(this);
30
		}
31

32 1
		signIn(_e, provider) {
33 1
			Auth.federatedSignIn({ provider });
34
		}
35

36 1
		render() {
37 1
			return <Comp {...this.props} OAuthSignIn={this.signIn} />;
38
		}
39 1
	};
40
}
41

42 1
const Button = (props: any) => (
43
	<SignInButton
44
		id={oAuthSignInButton}
45 0
		onClick={() => props.OAuthSignIn()}
46 1
		theme={props.theme || AmplifyTheme}
47
		variant={'oAuthSignInButton'}
48
	>
49 1
		<SignInButtonContent theme={props.theme || AmplifyTheme}>
50 1
			{I18n.get(props.label || 'Sign in with AWS')}
51
		</SignInButtonContent>
52
	</SignInButton>
53
);
54

55 1
export const OAuthButton = withOAuth(Button);
56

57
/**
58
 * @deprecated use named import
59
 */
60 1
export default withOAuth;

Read our documentation on viewing source code .

Loading