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

✨ hopefully working apple sign-in #38

Merged
merged 1 commit into from
Sep 26, 2024
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
9 changes: 9 additions & 0 deletions app/components/layout/LayoutLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ const providers = reactive<Provider[]>([
color: 'white',
click: async () => await navigateTo('/api/oauth/google', { external: true }),
},
{
name: 'apple',
label: 'Apple',
icon: 'i-mdi-apple',
color: 'white',
click: async () => await navigateTo('/api/oauth/redirect/apple', { external: true }),
},

/*
{
name: 'x',
Expand Down Expand Up @@ -56,6 +64,7 @@ const providers = reactive<Provider[]>([
icon: 'i-mdi-github',
click: async () => await navigateTo('/api/oauth/github', { external: true }),
},

])
</script>

Expand Down
33 changes: 33 additions & 0 deletions app/types/oauth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ export interface GoogleUserInfo {
email: string
email_verified: boolean
}
/*

apple user { iss: 'https://appleid.apple.com',
aud: 'fume.bio',
exp: 1727422907,
iat: 1727336507,
sub: '000563.30ae9239e35e4d2da5806a88600e772a.0716',
at_hash: 'PcyA1wqULsWWxgiiXSTGnQ',
email: '[email protected]',
email_verified: true,
auth_time: 1727336507,
nonce_supported: true }
*/
export interface AppleUserInfo {
aud: string
exp: number
iat: number
sub: string
at_hash: string
email: string
email_verified: boolean
auth_time: number
nonce_supported: boolean
}

export interface GithubUserInfo {
login: string
id: number
Expand Down Expand Up @@ -50,6 +75,14 @@ export interface GithubUserInfo {
updated_at: string
}

export interface AppleUserInfo {
name: {
firstName: string
lastName: string
}
email: string
}

export interface MicrosoftUserInfo {
id: string
displayName: string
Expand Down
6 changes: 6 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({

devtools: { enabled: true },
extends: ['@nuxt/ui-pro'],
modules: [
Expand Down Expand Up @@ -47,6 +48,11 @@ export default defineNuxtConfig({
maxAge: 60 * 60 * 24 * 365, // 1 year
name: 'fumebio-session',
},
apple: {
teamId: '',
keyIdentifier: '',
privateKey: '',
},
oauth: {
google: {
clientId: '',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@fullcalendar/vue3": "^6.1.15",
"@nuxt/ui-pro": "^1.4.3",
"@prisma/adapter-d1": "^5.20.0",
"apple-signin-auth": "^1.7.6",
"date-fns": "^4.1.0"
},
"devDependencies": {
Expand Down
109 changes: 109 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/api/[...slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Round } from '@prisma/client'
import { createRouter, useBase } from 'h3'
import type { Token, User } from '~/types/models'
import logout from '../controllers/logout'
import { githubHandler, googleHandler } from '../controllers/oauth'
import { appleHandler, appleRedirectHandler, githubHandler, googleHandler } from '../controllers/oauth'
import round from '../controllers/round'
import test from '../controllers/test'
import token from '../controllers/token'
Expand All @@ -24,6 +24,8 @@ if (useRuntimeConfig().appEnv === 'test')
router.post('/test/session', test.create)

router.get('/oauth/google', googleHandler)
router.get('/oauth/redirect/apple', appleRedirectHandler)
router.post('/oauth/apple', appleHandler)
// router.get('/oauth/facebook', facebookHandler)
// router.get('/oauth/instagram', instagramHandler)
// router.get('/oauth/x', xHandler)
Expand Down
Loading