Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sign in with apple #1494

Merged
merged 6 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ class API {
}

async oAuthLogin(type, query) {
if (type === 'apple') {
const authCode = query?.substring(1);
const { data } = await this.axiosInstance.post(
`/login/${type}/callback`,
{
state: 'cordova',
code: authCode
}
);
return data;
}
const { data } = await this.axiosInstance.get(
`/login/${type}/callback${query}`
);
Expand Down
30 changes: 30 additions & 0 deletions src/components/WelcomeScreen/WelcomeScreen.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Link from '@material-ui/core/Link';
import CloseIcon from '@material-ui/icons/Close';
import IconButton from '../UI/IconButton';
import {
AppleLoginButton,
FacebookLoginButton,
GoogleLoginButton
} from 'react-social-login-buttons';
Expand Down Expand Up @@ -94,6 +95,26 @@ export class WelcomeScreen extends Component {
}
};

handleAppleLoginClick = () => {
const intl = this.props.intl;
if (isIOS()) {
window.cordova.plugins.SignInWithApple.signin(
{ requestedScopes: [0, 1] },
function(succ) {
window.location.hash = `#/login/apple/callback?${
succ.authorizationCode
}`;
},
function(err) {
alert(intl.formatMessage(messages.loginErrorAndroid));
console.error(err);
}
);
return;
}
window.location = `${API_URL}login/apple-web`;
};

render() {
const { finishFirstVisit, heading, text, onClose } = this.props;
const { activeView } = this.state;
Expand Down Expand Up @@ -147,6 +168,15 @@ export class WelcomeScreen extends Component {
<FormattedMessage {...messages.facebook} />
</FacebookLoginButton>
)}

{!isAndroid() && !isElectron() && (
<AppleLoginButton
className="WelcomeScreen__button WelcomeScreen__button--google"
onClick={this.handleAppleLoginClick}
>
<FormattedMessage {...messages.apple} />
</AppleLoginButton>
)}
</div>

{!onClose && (
Expand Down
4 changes: 4 additions & 0 deletions src/components/WelcomeScreen/WelcomeScreen.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default defineMessages({
id: 'cboard.components.WelcomeScreen.google',
defaultMessage: 'Sign in with Google'
},
apple: {
id: 'cboard.components.WelcomeScreen.apple',
defaultMessage: 'Sign in with Apple'
},
skipForNow: {
id: 'cboard.components.WelcomeScreen.skipForNow',
defaultMessage: 'Skip for now'
Expand Down
1 change: 1 addition & 0 deletions src/translations/src/cboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cboard.components.WelcomeScreen.skipForNow": "Skip for now",
"cboard.components.WelcomeScreen.google": "Sign in with Google",
"cboard.components.WelcomeScreen.facebook": "Sign in with Facebook",
"cboard.components.WelcomeScreen.apple": "Sign in with Apple",
"cboard.components.WelcomeScreen.loginErrorAndroid": "Sorry. An error occurred during authenticate process. Please try it again",
"cboard.components.WelcomeScreen.terms": "Terms",
"cboard.components.WelcomeScreen.privacy": "Privacy Policy",
Expand Down