概要

@sidebase/nuxt-authのローカル認証を試す機会がありましたので、備忘録です。

背景

以下の記事で、@sidebase/nuxt-authを使って、Drupalの認証を行う方法を紹介しました。

上記の記事では、Nuxt3のSSRを利用して、@sidebase/nuxt-authのauthjsプロバイダを使用していました。プロバイダの説明は以下です。

authjs: for non-static apps that want to use Auth.js / NextAuth.js to offer the reliability & convenience of a 23k star library to the Nuxt 3 ecosystem with a native developer experience (DX)
local: for static pages that rely on an external backend with a credential flow for authentication. The Local Provider also supports refresh tokens since v0.9.0. Read more here.

(機械翻訳)authjs: 非静的なアプリ向けで、Auth.js / NextAuth.js を使用し、23,000以上のスターを持つ信頼性と利便性をNuxt 3エコシステムに提供します。開発者にネイティブな開発体験 (DX) を提供します。
local: 外部バックエンドを使用し、認証のために資格情報フローを利用する静的ページ向けです。このローカルプロバイダーは、バージョン0.9.0以降、リフレッシュトークンもサポートしています。詳しくはこちらをご覧ください。

アプリケーションをSSGなどで作成した際には、後者の方法を使用する必要があるかと思います。

ソースコード

リポジトリは以下です。

https://github.com/nakamura196/nuxt-auth-local-drupal

ソースコードは以下です。

ローカル認証を使用する場合には、next-authをインストールする必要はなく、@sidebase/nuxt-authのみでよいようでした。

{}""""}"}"}npts,d,daryc"""""e"""e"miprbdgpppnvvv@eveiueeroeuuuDs"a"pivnesnxeeei:t:tl"evtdt"-pdesd:riie":ree"""""aenn:onbn:m::"twsc"udauone"ti"ltesxtd{"u":ae^aenetrunx:ls3trc/-ulut"l".e"inaeex"n":1s:eup,"tdnu:5tsxp,eux{."""t"bvxt"1,l:-,u"tn"aai,pu,t{ulgrxetdeetsh"nvt",eip":rerawe"t"p^e,a0"r.,e9".4"

Drupalの認証を使用します。CMS_URLには、https://drupal.example.orgのような値を入れます。

試行錯誤の結果、特にsignIngetSessionを以下のように設定することで、最低限の動作確認ができました。

e}x)pcma};hooou,trmdtbp}ttpuhar,pal:sote}t}sdteevyn,o,:eis{Uipdsssg}ksthm/fb:Rdepiiie,eiyea/aiLe:ogggtpmngpaxnul[:rinnnSae:nedAuli":"nIOUettI:egxtt@pltnupshh{nretysr{os:t:s:oR"NI.dDioc::ideBanceadca{uo":semSofteel{{nnspaeemiebs"pd:e"or:c/n:as,apesgneodes.taf{sesr"noN"eehtiite"Xdcu2/n:hno"T,-ssx0nv:en,oC:/t2u."d/kSaC4xCu",teR3po-tMsuonF6in1-SeskP-0/f1a_reeoT0ci-uU/rnio,og0tRl"nkn(1hLl,tef{""goeni,]+igr"g,no:,u"?ur/_t"a"f"/t,o,cirsBommrenaefa/tt_rn=hteujoor1xsdkto:e使-nnc"""o,g,nefmtie"gth}o,d:"post"},
<cccc}<soooo;/t/cnnnns}se<trssssi)cmd/eittttgnp;rpi<<<dmpnaailvhpd/ipt{uphImspa>1>i<<dvlsaanestt>{vt/t/i>assesn(::>eY{>e<te<tvtetrsd{>ombemf/e>etanwlupudpumpo<<<fm>utaoesaaltplriiboppumrLesatatlamnnurlsedorsratoatpptmal,gnweente@uut>ta==iao}esttoensnmrc}@>un>girredu<-c-btt=gee=..r/ilemyyt"nffvvrpfilippytI((aae>=csteepsn""lln"ke.==e",""uuts=>p""=>))=eelt"rtp"d;;>,,yaseeasativxsut{{ugetsba{snn"wm,Otois=u=rtst=t"-d"ia=(hm">gt)aoSnu'"ndiOsa>de-guuSllmnt}tie=o}hgL"dI}.enouen<ngsl<=/tOie=/hiunr"bu1ct"npus>a<>aatet/mstAebesoudu"wnt'to>h"tpr(>old)na";>cephloalcdeehro=l"der="""

挙動

以下のようなログインフォームが表示されます。ユーザ名とパスワードを入力します。

statusloadingになります。

結果、以下のように表示されます。今回の実装ではdataに設定されるセッショントークンが表示されます。

まとめ

getSessionのエンドポイントは他のものにしたほうがよいかと思いますが、@sidebase/nuxt-authのローカル認証について、参考になりましたら幸いです。