Implement Google authentication (for Web) and user management system
This commit is contained in:
35
Bimix.UI.Shared/wwwroot/js/auth.js
Normal file
35
Bimix.UI.Shared/wwwroot/js/auth.js
Normal file
@@ -0,0 +1,35 @@
|
||||
window.initGoogleSignIn = async function(clientId) {
|
||||
try {
|
||||
if (!clientId) {
|
||||
throw new Error('ClientId is required');
|
||||
}
|
||||
|
||||
// Inicjalizacja Google Sign-In z dynamicznym ClientId
|
||||
google.accounts.id.initialize({
|
||||
client_id: clientId,
|
||||
callback: handleGoogleResponse,
|
||||
auto_select: false,
|
||||
cancel_on_tap_outside: true
|
||||
});
|
||||
|
||||
// Wyświetl popup logowania
|
||||
google.accounts.id.prompt((notification) => {
|
||||
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
||||
console.log('Google Sign-In popup not displayed');
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Google Sign-In initialization error:', error);
|
||||
DotNet.invokeMethodAsync('Bimix.UI.Shared', 'OnGoogleSignInError', error.message);
|
||||
}
|
||||
};
|
||||
|
||||
function handleGoogleResponse(response) {
|
||||
if (response.credential) {
|
||||
// Token otrzymany - wyślij do Blazor
|
||||
DotNet.invokeMethodAsync('Bimix.UI.Shared', 'OnGoogleSignInSuccess', response.credential);
|
||||
} else {
|
||||
DotNet.invokeMethodAsync('Bimix.UI.Shared', 'OnGoogleSignInError', 'No credential received');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user