Skip to content

Commit

Permalink
✨ hopefully working apple sign-in
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 26, 2024
1 parent 9f52438 commit 1d65ef7
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 31 deletions.
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: 'acidjazz@gmail.com',
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

0 comments on commit 1d65ef7

Please sign in to comment.